import { notificationManagementApi } from '/@/api/alarmManagement/alarmSettings/notificationManagements';
import { ref } from 'vue';
import { getEnum } from '/@/api';

const orgId = ref('');
const result = JSON.parse(sessionStorage.getItem('ORGID')!);
orgId.value = result;
const tableKeyMap = [
  {
    title: '序号',
    dataIndex: 'address',
    customRender: (text: any) => {
      return text.index + 1;
    },
  },
  {
    title: '优先级',
    dataIndex: 'prioritys',
  },
  {
    title: '告警类型',
    dataIndex: 'alarmTypeName',
  },
  {
    title: '告警标题',
    dataIndex: 'alarmTitle',
  },
  {
    title: '错误码',
    dataIndex: 'errorCode',
  },
  {
    title: '通知名单',
    dataIndex: 'notificationList',
    width: 150,
    textEllipsis: true,
  },
  {
    title: '通知方式',
    dataIndex: 'notificationMethod',
  },
  {
    title: '启用通知',
    dataIndex: 'enableNotifications',
  },
];
export const notificationtableConfig = (notificationManagements: any) => {
  return {
    title: '告警规则',
    api: notificationManagementApi.getTableList,
    headerActions: [],
    columns: tableKeyMap,
    columnActions: {
      title: '操作',
      actions: [
        {
          label: '联系方式',
          name: 'FeedBackDetail',
          dynamicParams: ['uuid', 'appealType'],
          handle: (data: any) => {
            notificationManagements.value.toggle(data);
          },
        },
      ],
    },

    formConfig: {
      schemas: [
        {
          field: 'alarmType',
          label: '告警类型',
          component: 'NsSelect',
          componentProps: {
            placeholder: '请选告警类型',
            allowClear: true,
            options: [
              {
                label: '设备告警',
                value: 1,
              },
              {
                label: '网关告警',
                value: 2,
              },
              {
                label: '能耗告警',
                value: 3,
              },
            ],
          },
        },
        {
          field: 'priority',
          label: '告警优先级',
          component: 'nsSelectApi',
          // dynamicParams: {
          //   id: 'deviceName', //帮定上级联动数据
          // },
          componentProps: {
            api: () => getEnum({ params: { enumType: 'PriorityEnum' } }),
            immediate: true,
            allowClear: true,
            resultField: 'data',
            labelField: 'label',
            valueField: 'value',
            placeholder: '请选择告警优先级',
            showSearch: true,
            filterOption: (input: string, option: any) => {
              return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
            },
            // autoSelectFirst: true,
          },
        },
        {
          field: 'alarmTitle',
          label: '告警标题',
          component: 'NsInput',
          componentProps: {
            allowClear: true,
            placeholder: '请输入告警标题关键字',
          },
        },
        {
          field: 'errorCode',
          label: '错误码',
          component: 'NsInput',
          componentProps: {
            allowClear: true,
            placeholder: '请输入告警错误码',
          },
        },
        {
          field: 'enableNotifications',
          label: '启用状态',
          component: 'NsSelect',
          componentProps: {
            allowClear: true,
            placeholder: '请选择启用状态',
            options: [
              {
                label: '启用',
                value: '1',
              },
              {
                label: '关闭',
                value: '0',
              },
            ],
          },
        },
      ],
    },
    params: { orgId: orgId.value },
    // pagination: { pageSizeOptions: false },
    rowKey: 'id',
  };
};
