import { alarmLevel, statusType } from '/@/views/device/list/config/detail.config';
import { FormSchema } from '/@/components/Form';
import { BasicColumn } from '/@/components/Table';
import moment from 'moment';

export enum AlarmStatus {
  CLEARED_UN_ACK = 'CLEARED_UNACK',
  ACTIVE_UN_ACK = 'ACTIVE_UNACK',
  CLEARED_ACK = 'CLEARED_ACK',
  ACTIVE_ACK = 'ACTIVE_ACK',
}

export enum AlarmStatusMean {
  CLEARED_UNACK = '清除未确认',
  ACTIVE_UNACK = '激活未确认',
  CLEARED_ACK = '清除已确认',
  ACTIVE_ACK = '激活已确认',
}

export const alarmSearchSchemas: FormSchema[] = [
  {
    field: 'status',
    label: '告警状态',
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: [
        {
          label: AlarmStatusMean[AlarmStatus.CLEARED_UN_ACK],
          value: AlarmStatus.CLEARED_UN_ACK,
        },
        {
          label: AlarmStatusMean[AlarmStatus.ACTIVE_UN_ACK],
          value: AlarmStatus.ACTIVE_UN_ACK,
        },
        {
          label: AlarmStatusMean[AlarmStatus.CLEARED_ACK],
          value: AlarmStatus.CLEARED_ACK,
        },
        {
          label: AlarmStatusMean[AlarmStatus.ACTIVE_ACK],
          value: AlarmStatus.ACTIVE_ACK,
        },
      ],
    },
  },
  {
    field: 'alarmType',
    label: '告警场景',
    component: 'Input',
    colProps: { span: 6 },
    componentProps: {
      maxLength: 255,
      placeholder: '请输入告警场景',
    },
    dynamicRules: () => {
      return [
        {
          required: false,
          validator: (_, value) => {
            if (String(value).length > 255) {
              return Promise.reject('字数不超过255个字');
            }
            return Promise.resolve();
          },
        },
      ];
    },
  },
  {
    field: 'alarmTime',
    label: '告警时间',
    component: 'RangePicker',
    componentProps: {
      showTime: { defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')] },
    },
    colProps: { span: 6 },
  },
];
export const alarmColumns: BasicColumn[] = [
  {
    title: '告警时间',
    dataIndex: 'createdTime',
    width: 120,
  },
  {
    title: '告警设备',
    dataIndex: 'deviceName',
    width: 100,
  },
  {
    title: '告警场景',
    dataIndex: 'type',
    width: 160,
  },
  {
    title: '告警级别',
    dataIndex: 'severity',
    width: 160,
    format: (text) => alarmLevel(text),
  },
  {
    title: '状态',
    dataIndex: 'status',
    format: (text) => statusType(text),
    width: 160,
  },
];

export const alarmSchemasForm: FormSchema[] = [
  {
    field: 'deviceName',
    label: '告警设备',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },

  {
    field: 'startTs',
    label: '开始时间',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'endTs',
    label: '结束时间',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'ackTs',
    label: '处理时间',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
    ifShow: ({ values }) => values.status === '激活已确认' || values.status === '清除已确认',
  },
  {
    field: 'clearTs',
    label: '清除时间',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
    ifShow: ({ values }) => values.status === '清除已确认' || values.status === '清除未确认',
  },
  {
    field: 'type',
    label: '告警场景',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'severity',
    label: '严重程度',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'details',
    label: '详情',
    component: 'InputTextArea',
  },
];
