import {
  MyBetaModalFormProps,
  MyButtons,
  MyFormItems,
  MyModalFormProps,
  rulesHelper,
} from '@/common';
import { Selects } from '@/components/Select';
import { Apis } from '@/gen/Apis';
import { OrganizationsTypeEnum } from '@/gen/Enums';
import { BetaSchemaForm } from '@ant-design/pro-components';
import { Form, message } from 'antd';

export default function Create(props: MyBetaModalFormProps) {
  const [form] = Form.useForm();

  return (
    <BetaSchemaForm<ApiTypes.Company.Organizations.Store>
      {...MyModalFormProps.props}
      title={`添加${props.title}`}
      wrapperCol={{ span: 24 }}
      width="500px"
      trigger={<MyButtons.Create title={`添加${props.title}`} />}
      form={form}
      onOpenChange={(open: any) => {
        if (open) {
          form.resetFields(); // 清空表单数据
        }
      }}
      onFinish={async (values) =>
        Apis.Company.Organizations.Store({
          ...values,
          companies_id: props?.item?.id,
        })
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        Selects?.OrganizationsTree({
          title: '上级组织',
          key: 'parent_id',
          params: { companies_id: props?.item?.id },
          colProps: { span: 24 },
        }),
        {
          key: 'name',
          title: '组织名称',
          colProps: { span: 24 },
          formItemProps: { ...rulesHelper.text },
        },
        MyFormItems.EnumRadio({
          key: 'type',
          title: '组织类型',
          colProps: { span: 24 },
          valueEnum: OrganizationsTypeEnum,
          required: true,
        }),
        // Selects?.Employees({
        //   title: '负责人',
        //   colProps: { span: 8 },
        // }),
        // {
        //   key: 'manager_phone',
        //   title: '负责人手机',
        //   colProps: { span: 8 },
        //   valueType: 'number',
        //   fieldProps: {
        //     maxLength: 11,
        //   },
        // },
        // {
        //   key: 'manager_email',
        //   title: '负责人邮箱',
        //   colProps: { span: 8 },
        // },
      ]}
    />
  );
}
