import { BasicColumn, FormSchema } from '@/components/Table';
import { h } from 'vue';
import { Tag,Switch } from 'ant-design-vue';
import Icon from '@/components/Icon/Icon.vue';
import {updateState} from '@/api/sys/WFSchemeInfo'
import { useMessage } from '@/hooks/web/useMessage';
const { createConfirm, createMessage } = useMessage();
export const columns: BasicColumn[] = [
  {
    title: '编号',
    dataIndex: 'code',
  },
  {
    title: '名称',
    dataIndex: 'name',
  },
  {
    title: '分类',
    dataIndex: 'category',
  },
  {
    title: '状态',
    dataIndex: 'enabledMark',
    width: 80,
    customRender: ({ record }) => {
      if (record.type == 2) {
        const color = 'blue';
        const text = '草稿';
        return h(Tag, { color: color }, () => text);
      } else {
        return h(Switch, {
          checked: record.enabledMark === 1,
          checkedChildren: '启用',
          unCheckedChildren: '停用',
          loading: record.pendingStatus,
          onChange(checked) {
            record.pendingStatus = true;
            const newStatus = checked ? 1 : 0;
            const { createMessage } = useMessage();
            updateState({ id: record.id, state: newStatus })
              .then((data) => {
                record.enabledMark = newStatus;
                createMessage.success('状态修改成功');
              })
              .catch((err) => {
                createMessage.success('状态修改失败');
              })
              .finally(() => {
                record.pendingStatus = false;
              });
          },
        });
      }
    },
  },
  {
    title: '创建人',
    dataIndex: 'createUserName',
  },
  {
    title: '创建时间',
    dataIndex: 'createDate',
  },

];

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

export const searchFormSchema: FormSchema[] = [
  {
    field: 'key',
    label: '关键字',
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'itemDetailId',
    label: '名称',
    component: 'Input',
    ifShow:false
  },
  {
    field: 'itemName',
    label: '名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'itemValue',
    label: '值',
    component: 'Input',
    required: true,
  },
  {
    field: 'sortCode',
    label: '排序',
    component: 'InputNumber',
  },
  {
    field: 'enabledMark',
    label: '是否有效',
    component: 'RadioButtonGroup',
    defaultValue: 1,
    componentProps: {
      options: [
        { label: '是', value: 0 },
        { label: '否', value: 1 },
      ],
    },
  },
  {
    field: 'description',
    label: '备注',
    component: 'InputTextArea',
  },
];

