/**
 * 灾害预警信息表单配置
 */
import { DISASTER_TYPE, DISASTER_LEVEL } from '@/views/disaster/constant';
import { WEATHER_DISASTER_ALERT_TYPE } from '../constant';
import type { FormConfig } from '@/types/basic-form';
// 通用表单信息
const BASIC_FROM_CONFIG = {
  DISASTER_LEVEL: {
    label: '灾害等级',
    prop: 'disasterLevel',
    component: 'ElSelect',
    componentProps: {
      placeholder: '请选择灾害等级',
      filterable: true,
      clearable: true,
    },
    selectOptions: DISASTER_LEVEL,
  },
  IS_PUSH: {
    label: '是否推送',
    prop: 'isPush',
    slot: 'isPush',
  },
  CREATE_USER: {
    label: '创建人',
    prop: 'createUser',
    component: 'ElInput',
    componentProps: {
      disabled: true,
    },
  },
};

// 预警信息表单信息
export const WARNING_INFO_FROM_CONFIG: FormConfig[] = [
  {
    label: '灾害类型',
    prop: 'disasterType',
    component: 'ElSelect',
    componentProps: {
      placeholder: '请选择灾害类型',
      filterable: true,
      clearable: true,
    },
    selectOptions: WEATHER_DISASTER_ALERT_TYPE,
  },
  BASIC_FROM_CONFIG.DISASTER_LEVEL,
  {
    label: '预警时间',
    prop: 'warningTime',
    component: 'ElDatePicker',
    componentProps: {
      placeholder: '请选择预警时间',
      type: 'datetime',
      format: 'YYYY-MM-DD HH:mm',
      dateFormat: 'MMM DD, YYYY',
      timeFormat: 'HH:mm',
    },
  },
  {
    label: '信息来源',
    prop: 'source',
    component: 'ElInput',
    componentProps: {
      placeholder: '国家预警信息发布中心',
    },
  },
  {
    label: '发布内容',
    prop: 'warningContent',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入发布内容',
      type: 'textarea',
      rows: 5,
      maxlength: 1000,
      showWordLimit: true,
    },
  },
  BASIC_FROM_CONFIG.IS_PUSH,
  BASIC_FROM_CONFIG.CREATE_USER,
];

// 防御通知表单信息
export const DEFENSE_NOTICE_FROM_CONFIG: FormConfig[] = [
  {
    label: '灾害类型',
    prop: 'disasterType',
    component: 'ElSelect',
    componentProps: {
      placeholder: '请选择灾害类型',
      filterable: true,
      clearable: true,
    },
    selectOptions: DISASTER_TYPE,
  },
  BASIC_FROM_CONFIG.DISASTER_LEVEL,
  {
    label: '通知标题',
    prop: 'noticeTitle',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入通知标题',
      maxlength: 200,
      showWordLimit: true,
    },
  },
  {
    label: '通知内容',
    prop: 'noticeContent',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入通知内容',
      type: 'textarea',
      rows: 5,
      maxlength: 1000,
      showWordLimit: true,
    },
  },
  {
    label: '通知附件',
    prop: 'noticeAttachment',
    slot: 'noticeAttachment',
  },
  BASIC_FROM_CONFIG.IS_PUSH,
  BASIC_FROM_CONFIG.CREATE_USER,
];

// 通用表单数据
const BASIC_FROM_DATA = {
  disasterType: '',
  disasterLevel: '',
  userGroupList: [],
  isPush: null,
  createUser: '',
};

// 预警信息表单数据
export const WARNING_INFO_FROM_DATA = {
  ...BASIC_FROM_DATA,
  warningTime: '',
  source: '',
  warningContent: '',
};

// 防御通知表单数据
export const DEFENSE_NOTICE_FROM_DATA = {
  ...BASIC_FROM_DATA,
  noticeTitle: '',
  noticeContent: '',
  noticeAttachment: [],
};

// 通用表单规则
const BASIC_FROM_RULES = {
  disasterType: [{ required: true, message: '请选择灾害类型', trigger: 'change' }],
  disasterLevel: [
    {
      required: true,
      message: '请选择灾害等级',
      trigger: 'change',
    },
  ],
  userGroupList: [{ required: true, message: '请选择用户组', trigger: 'change' }],
  isPush: [{ required: true, message: '请选择是否推送', trigger: 'change' }],
};

// 预警信息表单规则
export const WARNING_INFO_FROM_RULES = {
  ...BASIC_FROM_RULES,
  warningTime: [{ required: true, message: '请选择预警时间', trigger: 'change' }],
  source: [{ required: true, message: '请输入信息来源', trigger: 'blur' }],
};

// 防御通知表单规则
export const DEFENSE_NOTICE_FROM_RULES = {
  ...BASIC_FROM_RULES,
  noticeTitle: [{ required: true, message: '请输入通知标题', trigger: 'blur' }],
  noticeContent: [{ required: true, message: '请输入通知内容', trigger: 'blur' }],
  noticeAttachment: [{ required: true, message: '请上传通知附件', trigger: 'change' }],
};
