import {
  MyBetaModalFormProps,
  MyButtons,
  MyModalFormProps,
  rulesHelper,
} from '@/common';
import { Selects } from '@/components/Select';
import { Apis } from '@/gen/Apis';
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.CompanyPositions.Store>
      {...MyModalFormProps.props}
      title={`添加岗位`}
      wrapperCol={{ span: 24 }}
      width="500px"
      trigger={<MyButtons.Create title={`添加岗位`} />}
      form={form}
      onOpenChange={(open: any) => {
        if (open) {
          form.resetFields(); // 清空表单数据
        }
      }}
      onFinish={async (values) =>
        Apis.Company.CompanyPositions.Store({
          ...values,
          companies_id: values?.companies_id || props?.item?.id,
        })
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        ...(props?.item?.id
          ? []
          : [
              Selects?.Companies({
                key: 'companies_id',
                title: '公司',
                colProps: { span: 24 },
                required: true,
              }),
            ]),
        {
          key: 'name',
          title: '岗位名称',
          colProps: { span: 24 },
          formItemProps: { ...rulesHelper.text },
        },
        {
          key: 'code',
          title: '岗位编号',
          colProps: { span: 24 },
          // formItemProps: { ...rulesHelper.text },
        },
        // {
        //   key: 'sort',
        //   title: '岗位排序',
        //   colProps: { span: 24 },
        //   valueType: 'number',
        // },
        {
          key: 'remark',
          title: '备注',
          colProps: { span: 24 },
          valueType: 'textarea',
        },
      ]}
    />
  );
}
