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

// 知识库类别数据模型
export interface KnowledgeType {
  id: string;
  name: string;
  icon: string;
  description: string;
  admin: string;
  applicableEnd: string;
  applicablePost: string;
  createTime: string;
  createUser: string;
}

// 查询表单配置
export const queryFormSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'name',
    label: '名称',
    componentProps: {
      placeholder: '请输入知识库类别名称',
      allowClear: true,
    },
  },
  {
    component: 'Input',
    fieldName: 'description',
    label: '描述',
    componentProps: {
      placeholder: '请输入知识库类别描述',
      allowClear: true,
    },
  },
];

// 抽屉表单配置
export const drawerFormSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
    fieldName: 'id',
  },

  {
    component: 'Input',
    fieldName: 'name',
    label: '知识库名称',
    componentProps: {
      placeholder: '请输入知识库名称',
      maxlength: 100,
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'description',
    label: '知识库描述',
    componentProps: {
      placeholder: '请输入知识库描述',
      maxlength: 200,
      type: 'textarea',
      showWordLimit: true,
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'icon',
    label: '知识图标',
    // 使用插槽自定义上传组件
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'admin',
    label: '知识库管理员',
    componentProps: {
      placeholder: '请输入知识库管理员',
      maxlength: 50,
    },
    rules: 'required',
  },
  {
    component: 'Select',
    componentProps: {
      placeholder: '请选择适用端',
      options: [
        { label: '钉钉', value: 'dingtalk' },
        { label: 'PC', value: 'pc' },
      ],
    },
    fieldName: 'applicableEnd',
    label: '适用端',
    rules: 'required',
  },
  {
    component: 'Select',
    componentProps: {
      placeholder: '请选择适用岗位',
      options: [
        { label: '管理员', value: 'admin' },
        { label: '普通用户', value: 'user' },
        { label: '技术人员', value: 'tech' },
      ],
    },
    fieldName: 'applicablePost',
    label: '适用岗位',
    rules: 'required',
  },
];

// 表格列配置
export const tableColumns: VxeGridProps['columns'] = [
  {
    type: 'checkbox',
    width: 60,
  },
  {
    field: 'icon',
    slots: { default: 'icon' },
    title: '类别图标',
    minWidth: 100,
  },
  {
    field: 'id',
    title: '类别ID',
    width: 80,
  },
  {
    field: 'name',
    title: '类别名称',
    minWidth: 120,
  },

  {
    field: 'description',
    title: '类别描述',
    minWidth: 150,
  },
  {
    field: 'admin',
    title: '管理员',
    minWidth: 100,
  },
  {
    field: 'applicableEnd',
    title: '适用端',
    minWidth: 100,
    formatter: (params: { cellValue: string }) => {
      const options = [
        { label: '钉钉', value: 'dingtalk' },
        { label: 'PC', value: 'pc' },
      ];
      const option = options.find((item) => item.value === params.cellValue);
      return option ? option.label : params.cellValue;
    },
  },
  {
    field: 'applicablePost',
    title: '适用岗位',
    minWidth: 100,
    formatter: (params: { cellValue: string }) => {
      const options = [
        { label: '管理员', value: 'admin' },
        { label: '普通用户', value: 'user' },
        { label: '技术人员', value: 'tech' },
      ];
      const option = options.find((item) => item.value === params.cellValue);
      return option ? option.label : params.cellValue;
    },
  },
  {
    field: 'createUser',
    title: '创建人',
    minWidth: 100,
  },
  {
    field: 'createTime',
    title: '创建时间',
    minWidth: 150,
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 180,
  },
];
