import { Form, Select } from "antd";
import { FormDatas } from "./interface";
import { useEffect, useState } from "react";
import baseHttp from "@/service/base";
const { Option } = Select;
export const FormSelect = (v: FormDatas) => {
  const [list, setList] = useState<any>([]);
  useEffect(() => {
    if (v.selectList && v.selectList.length > 0) {
      setList(v.selectList);
    } else {
      baseHttp.get(`${v.selectUrl}/?size=50&offset=1` ?? "", "").then((res) => {
        setList(res.data.record ?? []);
      });
    }
  }, [v.selectUrl, v.selectList]);
  return (
    <Form.Item key={v.label} label={v.label} name={v.name} rules={v.rules}>
      <Select placeholder="">
        {list?.map((v: any) => {
          return (
            <Option key={v.id} value={v.id}>
              {v.name}
            </Option>
          );
        })}
      </Select>
    </Form.Item>
  );
};
