import { ALG, PackageField, PackageType } from './packageDetail.config';
import { FormSchema } from '/@/components/Form';

export const formSchema: FormSchema[] = [
  {
    field: PackageField.TITLE,
    label: '标题',
    component: 'Input',
    colProps: { span: 12 },
  },
  {
    field: PackageField.VERSION,
    label: '版本',
    component: 'Input',
    colProps: { span: 12 },
  },
  {
    field: PackageField.VERSION_TAG,
    label: '版本标签',
    component: 'Input',
  },
  {
    field: PackageField.DEVICE_PROFILE_INFO,
    label: '所属产品',
    component: 'Input',
  },
  {
    field: PackageField.PACKAGE_TYPE,
    label: '包类型',
    component: 'Select',
    rules: [{ required: true, message: '包类型为必填项' }],
    componentProps: () => {
      return {
        options: [
          { label: '固件', value: PackageType.FIRMWARE },
          { label: '软件', value: PackageType.SOFTWARE },
        ],
        placeholder: '请选择所属产品',
      };
    },
  },
  {
    field: PackageField.URL,
    label: '直接URL',
    component: 'Input',
    ifShow: ({ model }) => {
      return model[PackageField.URL];
    },
    componentProps: {
      maxLength: 255,
    },
  },
  {
    field: PackageField.CHECK_SUM_ALG,
    label: '校验和算法',
    component: 'Select',
    colProps: { span: 12 },
    ifShow: ({ model }) => {
      return !model[PackageField.URL];
    },
    componentProps: {
      placeholder: '请选择校验和算法',
      options: Object.keys(ALG).map((key) => {
        return {
          label: String(ALG[key]).toUpperCase(),
          value: ALG[key],
        };
      }),
    },
  },
  {
    field: PackageField.CHECK_SUM,
    label: '校验和',
    component: 'Input',
    ifShow: ({ model }) => {
      return !model[PackageField.URL];
    },
    colProps: { span: 12 },
  },
  {
    field: PackageField.FILE_NAME,
    label: '文件名',
    component: 'Input',
    ifShow: ({ model }) => {
      return !model[PackageField.URL];
    },
    colProps: { span: 8 },
  },
  {
    field: PackageField.FILE_SIZE,
    label: '文件大小(以字节为单位)',
    component: 'Input',
    ifShow: ({ model }) => {
      return !model[PackageField.URL];
    },
    colProps: { span: 8 },
  },
  {
    field: PackageField.FILE_NAME,
    label: '文件名',
    component: 'Input',
    ifShow: ({ model }) => {
      return !model[PackageField.URL];
    },
    colProps: { span: 8 },
  },
  {
    field: PackageField.FILE_TYPE,
    label: '内容类型',
    ifShow: ({ model }) => {
      return !model[PackageField.URL];
    },
    component: 'Input',
  },
  {
    field: PackageField.DESCRIPTION,
    label: '描述',
    component: 'Input',
  },
];
