import { Form } from 'antd';
import { useEffect } from 'react';
import BindDataItem from './BindDataItem';
interface BindDataFromProps {
  value?: any;
  onChange?: (value: any) => void;
  flagList?: any;
  isHaveDate?: boolean;
  isHaveDay?: boolean;
  isHaveCheckBox?: boolean;
  activeKey?: any;
  disabledIds?: string[];
  isAllowApply?: boolean;
  setActiveKey?: (val: string[]) => void;
  selectMap?: any;
  getSelectOptions?: (id: number) => void;
  appId?: number;
  customRender?: (name: React.ReactNode, item: any) => React.ReactNode;
  checkInterceptor?: (checked: any, info: any) => Promise<boolean>;
  isOtherUser?: boolean;
  fixedIds?: string[];
}
const BindDataFrom = ({
  value,
  onChange,
  flagList,
  disabledIds,
  isAllowApply = false,
  isHaveDate,
  isHaveDay,
  activeKey,
  isHaveCheckBox = false,
  setActiveKey,
  selectMap,
  getSelectOptions,
  appId,
  customRender,
  checkInterceptor,
  isOtherUser,
  fixedIds,
}: BindDataFromProps) => {
  const [form] = Form.useForm();
  useEffect(() => {
    form.setFieldsValue(value);
  }, [value, form]);
  return (
    <Form
      form={form}
      onValuesChange={async (changedValues, allValues) => {
        onChange?.(allValues);
      }}
    >
      <BindDataItem
        isAllowApply={isAllowApply}
        disabledIds={disabledIds}
        flagList={flagList}
        isHaveDate={isHaveDate}
        isHaveDay={isHaveDay}
        isHaveCheckBox={isHaveCheckBox}
        activeKey={activeKey}
        setActiveKey={setActiveKey}
        selectMap={selectMap}
        getSelectOptions={getSelectOptions}
        appId={appId}
        customRender={customRender}
        checkInterceptor={checkInterceptor}
        fixedIds={fixedIds}
        isOtherUser={isOtherUser}
      />
    </Form>
  );
};
export default BindDataFrom;
