import { type FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { DictEnum } from '@vben/constants';
import { getPopupContainer } from '@vben/utils';

import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render'
import { log } from 'console'

export const querySchema: FormSchemaGetter = () => [
  {
    label: '人员标签',
    fieldName: 'rosterType',
    component: 'Select',
    componentProps: {
      options: getDictOptions('roster_type'),
    },
  },
  {
    component: 'Input',
    fieldName: 'imgName',
    label: '人像名称',
  },
  {
    component: 'Select',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.SYS_USER_SEX),
    },
    fieldName: 'sex',
    label: '性别',
  },
];

// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// export const columns: () => VxeGridProps['columns'] = () => [
export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  /*  {
    title: '人员库编码',
    field: 'libCode',
  },*/
  {
    title: '人像名称',
    field: 'imgName',
  },
  {
    title: '性别',
    field: 'sex',
    slots:{
      default: ({row}) =>{
        return renderDict(row.sex, 'sys_user_sex')
      }
    }
  },
  {
    title: '邮箱',
    field: 'email',
  },
  {
    title: '联系方式',
    field: 'tel',
  },
  {
    title: '证件类型',
    field: 'certificateType',
    slots:{
      default: ({row}) =>{
        return renderDict(row.certificateType, 'sys_certificate_type')
      }
    }
  },
  {
    title: '证件号码',
    field: 'certificateNo',
  },
  {
    title: '出生日期',
    field: 'birthDate',
  },
  {
      title: '人员标签',
      field: 'rosterType',
      slots: {
        default: ({ row }) => {
          return renderDict(row.rosterType, 'roster_type')
        },
      },
      width: 100,
    },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 180,
  },
];

const test = getDictOptions('roster_type');
test.forEach(item => {
  console.log('item',item)  
});

export const modalSchema: FormSchemaGetter = () => [
  {
    label: '人员标签',
    fieldName: 'rosterType',
    component: 'Select',
    rules: 'required',
    componentProps: {
      options: getDictOptions('roster_type'),
    },
  },
  {
    label: '人像名称',
    fieldName: 'imgName',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '性别',
    fieldName: 'sex',
    component: 'Select',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.SYS_USER_SEX),
    },
  },
  {
    label: '邮箱',
    fieldName: 'email',
    component: 'Input',
  },
  {
    label: '联系方式',
    fieldName: 'tel',
    component: 'Input',
  },
  {
    label: '证件类型',
    fieldName: 'certificateType',
    component: 'Select',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.SYS_CERTIFICATE_TYPE),
    },
  },
  {
    label: '证件号码',
    fieldName: 'certificateNo',
    component: 'Input',
  },
  {
    label: '出生日期',
    fieldName: 'birthDate',
    component: 'Input',
  },
  {
    label: '人像图片',
    fieldName: 'imgOssId',
    component: 'ImageUpload',
    componentProps: {
      // accept: 'image/*', // 可选拓展名或者mime类型 ,拼接
      maxCount: 1, // 最大上传文件数 默认为1 为1会绑定为string而非string[]类型
    },
    formItemClass: 'col-span-2',
  },
];
