import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
import type { configAlarmApi } from '#/api';

import { $t } from '#/locales';

/**
 * 获取表格列配置
 * @description 使用函数的形式返回列数据而不是直接export一个Array常量，是为了响应语言切换时重新翻译表头
 * @param onActionClick 表格操作按钮点击事件
 */
export const useColumns = (
  onActionClick: OnActionClickFn<configAlarmApi.Alarm>,
): VxeTableGridOptions<configAlarmApi.Alarm>['columns'] => {
  return [
    {
      field: 'org_id',
      title: $t('config.Alarm.org_id'),
      width: 150,
    },
    {
      field: 'type',
      title: $t('config.Alarm.type'),
    },
    {
      field: 'value',
      title: $t('config.Alarm.value'),
      width: 150,
    },
    {
      align: 'right',
      cellRender: {
        attrs: {
          nameField: 'name',
          nameTitle: $t('system.dept.name'),
          onClick: onActionClick,
        },
        name: 'CellOperation',
        options: [
          // {
          //   code: 'append',
          //   text: '新增下级',
          // },
          'edit', // 默认的编辑按钮
          {
            code: 'delete', // 默认的删除按钮
            disabled: (_row: configAlarmApi.Alarm) => {
              return false;
              // return !!(row.children && row.children.length > 0);
            },
          },
        ],
      },
      field: 'operation',
      fixed: 'right',
      headerAlign: 'center',
      showOverflow: false,
      title: $t('system.dept.operation'),
      width: 200,
    },
  ];
};
export function useCreateSchema(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      fieldName: 'orgId',
      label: $t('config.Alarm.org_id'),
      disabled: true,
      // required: true,
    },
    {
      component: 'Input',
      fieldName: 'type',
      label: $t('config.Alarm.type'),
      disabled: true,
    },
    {
      component: 'Select',
      fieldName: 'key',
      label: $t('config.Alarm.key'),
      componentProps: {
        class: 'w-full',
        options: [
          {
            label: $t('config.Alarm.email'),
            value: 'email',
          },
          {
            label: $t('config.Alarm.phone'),
            value: 'phone',
          },
        ],
      },
    },
    {
      component: 'Input',
      fieldName: 'value',
      label: $t('config.Alarm.value'),
    },
  ];
}
export function useEditSchema(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      fieldName: 'id',
      label: $t('config.Alarm.id'),
      disabled: true,
    },
    {
      component: 'Input',
      fieldName: 'org_id',
      label: $t('config.Alarm.org_id'),
      disabled: true,
    },
    {
      component: 'Input',
      fieldName: 'type',
      label: $t('config.Alarm.type'),
      disabled: true,
    },
    {
      component: 'Select',
      fieldName: 'key',
      label: $t('config.Alarm.key'),
      componentProps: {
        class: 'w-full',
        options: [
          {
            label: $t('config.Alarm.phone'),
            value: 'phone',
          },
          {
            label: $t('config.Alarm.email'),
            value: 'email',
          },
        ],
      },
    },
    {
      component: 'Input',
      fieldName: 'value',
      label: $t('system.user.email'),
    },
  ];
}
