import {
  MyBetaModalFormProps,
  MyButtons,
  MyModalFormProps,
  rulesHelper,
} from '@/common';
import { SysSelects } from '@/components/SysSelects';
import { Apis } from '@/gen/Apis';
import { BetaSchemaForm } from '@ant-design/pro-components';
import { message } from 'antd';

export default function Create(props: MyBetaModalFormProps) {
  return (
    <BetaSchemaForm<ApiTypes.Common.Admins.Store>
      {...MyModalFormProps.props}
      title={`添加${props.title}`}
      wrapperCol={{ span: 24 }}
      width="500px"
      trigger={<MyButtons.Create title={`添加${props.title}`} />}
      onFinish={async (values) =>
        Apis.Common.Admins.Store(values)
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        {
          key: 'username',
          title: '用户名',
          formItemProps: { ...rulesHelper.text },
        },
        {
          key: 'password',
          title: '密码',
          valueType: 'password',
          formItemProps: { ...rulesHelper.text },
        },
        SysSelects.SysRoles(),
      ]}
    />
  );
}
