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

import { categoryTree } from '#/api/workflow/category';

export const queryFormSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'categoryName',
    label: '分类名称',
  },
];

export const tableColumns: VxeGridProps['columns'] = [
  {
    field: 'categoryName',
    title: '分类名称',
    treeNode: true,
  },
  {
    field: 'orderNum',
    title: '排序',
  },
  {
    field: 'createTime',
    title: '创建时间',
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    resizable: false,
    title: '操作',
    width: 230,
  },
];

export const drawerFormSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    dependencies: {
      if: () => false,
      triggerFields: [''],
    },
    fieldName: 'isUpdate',
  },
  {
    component: 'Input',
    dependencies: {
      if: () => false,
      triggerFields: [''],
    },
    fieldName: 'categoryId',
  },
  {
    component: 'ApiTreeSelect',
    componentProps: {
      api: async () => {
        return await categoryTree();
      },
      clearable: true,
      labelField: 'label',
      valueField: 'id',
      childrenField: 'children',
      checkStrictly: true,
    },
    dependencies: {
      // if(values) {
      //   // 总是显示上级分类选择框，无论是新增还是编辑
      //   return true;
      // },
      triggerFields: ['parentId'],
    },
    fieldName: 'parentId',
    label: '上级分类',
    // rules: 'selectRequired',
    defaultValue: 1,
  },
  {
    component: 'Input',
    fieldName: 'categoryName',
    label: '分类名称',
    rules: 'required',
  },
  {
    component: 'InputNumber',
    fieldName: 'orderNum',
    label: '排序',
  },
];
