import { View } from "@tarojs/components";
import { Radio } from "@taroify/core";
interface FormRadioProps {
  value: string | number;
  onChange: (value: string | number) => void;
  option: string[] | { label: string; value: string }[];
}

const FormRadio = (props: FormRadioProps) => {
  const { value, onChange, option } = props;

  let optionTemp = [...option] as {
    label: string;
    value: string;
  }[];
  optionTemp = optionTemp.map((v) => {
    if (typeof v === "string") return { label: v, value: v };
    return v;
  });

  return (
    <View style={{ width: "100%" }}>
      <Radio.Group onChange={(e) => onChange(e)} value={value}>
        {optionTemp.map((item) => {
          return <Radio name={item.value}>{item.label}</Radio>;
        })}
      </Radio.Group>
    </View>
  );
};

export default FormRadio;
