import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import { Icon } from '/@/components/Icon';
import { useI18n } from '/@/hooks/web/useI18n';
import { structureList } from '/@/api/sys/menu';
import { copyTransFun } from '/@/utils/fnUtils';
const { t } = useI18n();

//菜单管理页，所需的列 配置
export const columns: BasicColumn[] = [
  {
    title: '机构名称',
    dataIndex: 'departName',
    // width: 180,
    align: 'left',
  },
  {
    title: '机构ID',
    dataIndex: 'id',
    width: 320,
  },
  // {
  //   title: '父级ID',
  //   dataIndex: 'parentId',
  //   width: 250,
  // },
  {
    title: '排序',
    dataIndex: 'orderId',
    // width: 50,
  }
];

const isDir = (type: string) => type === '0';
const isMenu = (type: string) => type === '1';
const isButton = (type: string) => type === '2';

//菜单管理页，所需的搜索内容
export const searchFormSchema: FormSchema[] = [
  {
    field: 'menuName',
    label: t('routes.common.system.tableTitleSystemMenuName'), //菜单名称
    // label: '菜单名称',
    component: 'Input',
    colProps: { span: 8 },
    componentProps: {
      maxLength: 255,
    },
    dynamicRules: () => {
      return [
        {
          required: false,
          validator: (_, value) => {
            if (String(value).length > 255) {
              return Promise.reject('字数不超过255个字');
            }
            return Promise.resolve();
          },
        },
      ];
    },
  },
  {
    field: 'status',
    label: t('routes.common.system.tableTitleSystemStatus'), //状态
    // label: '状态',
    component: 'Select',
    componentProps: {
      options: [
        { label: t('routes.common.system.tableTitleSystemEnable'), value: '0' },
        // { label: '启用', value: '0' },

        { label: t('routes.common.system.tableTitleSystemStop'), value: '1' },
        // { label: '停用', value: '1' },
      ],
    },
    colProps: { span: 8 },
  },
];

//----------------------------------新增、编辑----------------------------------------------------------
export const formSchema: FormSchema[] = [
  {
    field: 'departName',
    label: '机构名称',
    component: 'Input',
    componentProps: {
      maxLength: 255,
      placeholder: '请输入角色名称',
    },
  },
  {
    label: '机构排序',
    field: 'orderId',
    component: 'Input',
    componentProps: {
      maxLength: 255,
      placeholder: '请输入排序',
    },
  },
  {
    field: 'pid',
    component: 'ApiTreeSelect',
    label: '父级机构',
    componentProps: {
      placeholder: '请选择父级机构',
      api: async () => {
        return await structureList();
      },
      onChange(value) {
        pid.value = value;
      },
    },
  },
];
