import { Form, Input, Select, Checkbox } from 'antd';
import { USER_TYPE_OPTIONS, LANGUAGE_OPTIONS, EMPLOYEE_OPTIONS } from './usersConstants';

interface Props {
  mode: 'create' | 'edit';
  disabled?: boolean;
}

export default function UserFormFields({ mode, disabled = false }: Props) {
  return (
    <>
      <Form.Item
        label="用户名"
        name="username"
        rules={
          mode === 'create'
            ? [
                { required: true, message: '请输入用户名' },
                {
                  pattern: /^[A-Za-z0-9_]{3,20}$/,
                  message: '用户名必须为 3-20 位字母数字下划线',
                },
              ]
            : []
        }
      >
        <Input
          placeholder="3-20 位字母数字下划线"
          disabled={disabled || mode === 'edit'}
          autoComplete="off"
        />
      </Form.Item>

      <Form.Item
        label="用户号"
        name="userCode"
        rules={[
          { required: true, message: '请输入用户号' },
          { max: 50, message: '用户号不能超过 50 字符' },
        ]}
      >
        <Input placeholder="用户号" disabled={disabled} />
      </Form.Item>

      <Form.Item
        label="类型"
        name="userType"
        rules={[{ required: true, message: '请选择类型' }]}
      >
        <Select options={USER_TYPE_OPTIONS as any} disabled={disabled} />
      </Form.Item>

      <Form.Item
        label="语言"
        name="language"
        rules={[{ required: true, message: '请选择语言' }]}
      >
        <Select options={LANGUAGE_OPTIONS as any} disabled={disabled} />
      </Form.Item>

      <Form.Item label="单据修改权限" name="canEditDocument" valuePropName="checked">
        <Checkbox disabled={disabled}>允许修改</Checkbox>
      </Form.Item>

      <Form.Item label="员工名" name="employeeId">
        <Select
          options={EMPLOYEE_OPTIONS}
          disabled={disabled}
          allowClear
          placeholder="可选，不选 = 无关联"
        />
      </Form.Item>
    </>
  );
}
