import dayjs from 'dayjs';
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { TreeItem } from '/@/components/Tree/index';
import { ModuleDataChart } from '/@/components/Configurable/types';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';

// 实时数据相关
export const columns: BasicColumn[] = [
  // {
  //   title: '序号',
  //   dataIndex: 'orderNo',
  //   width: 60,
  // },
  // {
  //   title: '区域',
  //   dataIndex: 'coalSeamName',
  //   width: 80,
  // },
  {
    title: '煤矿名称',
    dataIndex: 'mineName',
    width: 200,
  },
  {
    title: '密闭名称',
    dataIndex: 'devicePos',
    width: 100,
  },
  {
    title: '所属煤层',
    dataIndex: 'coalSeamName',
    width: 100,
  },
  {
    title: 'CO(ppm)',
    dataIndex: 'coVal',
    width: 100,
  },
  {
    title: 'CO2(%)',
    dataIndex: 'co2Val',
    width: 100,
  },
  {
    title: 'CH4(%)',
    dataIndex: 'ch4Val',
    width: 100,
  },
  {
    title: 'C2H2(ppm)',
    dataIndex: 'c2h2Val',
    width: 100,
  },
  {
    title: 'C2H4(%)',
    dataIndex: 'c2h4Val',
    width: 100,
  },
  {
    title: 'O2(%)',
    dataIndex: 'o2Val',
    width: 100,
  },
  {
    title: '温度(℃)',
    dataIndex: 'temperature',
    width: 100,
  },
  {
    title: '压差(Pa)',
    dataIndex: 'sourcePressure',
    width: 100,
  },
  {
    title: '自然发火隐患等级',
    dataIndex: 'fireAlarm',
    width: 100,
    customRender({ record }) {
      return tagCellRender(record.fireAlarm);
    },
  },
  {
    title: '是否漏风',
    dataIndex: 'leakageAlarm',
    width: 100,
    customRender({ record }) {
      return tagCellRender(record.leakageAlarm);
    },
  },
  {
    title: '压差隐患等级',
    dataIndex: 'sourcePressureAlarm',
    width: 100,
    customRender({ record }) {
      return tagCellRender(record.sourcePressureAlarm);
    },
  },
  {
    title: '密闭启封判定',
    dataIndex: 'unsealAlarm',
    width: 100,
    customRender({ record }) {
      return tagCellRender(record.unsealAlarm);
    },
  },
  // {
  //   title: '爆炸危险性',
  //   dataIndex: 'explosionHazard',
  //   width: 80,
  // },
  {
    title: '更新时间',
    dataIndex: 'readTime',
    width: 100,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'mineCode',
    label: '煤矿名称',
    component: 'MineCascader',
    slot: 'mine-cascader',
    colProps: { span: 6 },
  },
  {
    field: 'mineNameAbbr',
    label: '煤矿简称',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'productStatus',
    label: '生产状态',
    component: 'Select',
    componentProps: {
      options: [
        { label: '拟建矿井', value: '0' },
        { label: '正常生产矿井', value: '1' },
        { label: '长期停产矿井', value: '1' },
      ],
    },
    colProps: { span: 6 },
  },
  {
    field: 'riskLevel',
    label: '自燃情况',
    component: 'Select',
    componentProps: {
      options: [
        { label: 'Ⅰ类容易自燃', value: '0' },
        { label: 'Ⅱ类自燃', value: '1' },
        { label: 'Ⅲ类不易自燃', value: '2' },
      ],
    },
    colProps: { span: 6 },
  },
];

export const modalDetailsData: {
  basicInfo: Record<string, any>[];
  board: Record<string, any>[];
  gasConcentrationConfig: ModuleDataChart;
  pressureConfig: ModuleDataChart;
} = {
  basicInfo: [
    {
      label: '煤矿名称',
      value: 'mineName',
      tag: false,
    },
    {
      label: '设备位置',
      value: 'devicePos',
      tag: false,
    },
    // {
    //   label: '所属煤层',
    //   value: 'coalSeamName',
    // },
    // {
    //   label: '自燃情况',
    //   value: 'Ⅰ类容易自燃',
    // },
    {
      label: '自然发火隐患等级',
      value: 'fireAlarm',
      tag: true,
    },
    {
      label: '是否漏风',
      value: 'leakageAlarm',
      tag: true,
    },
    {
      label: '压差隐患等级',
      value: 'sourcePressureAlarm',
      tag: true,
    },
    {
      label: '密闭启封判定',
      value: 'unsealAlarm',
      tag: true,
    },
  ],
  board: [
    {
      label: 'CO(ppm)',
      value: 'coVal',
    },
    {
      label: 'CO2(PPM)',
      value: 'co2Val',
    },
    {
      label: 'O2(%)',
      value: 'o2Val',
    },
    {
      label: 'CH4(%)',
      value: 'ch4Val',
    },
    {
      label: 'C2H4(ppm)',
      value: 'c2h4Val',
    },
    {
      label: 'C2H2(ppm)',
      value: 'c2h2Val',
    },
    {
      label: '温度(℃)',
      value: 'temperature',
    },
    {
      label: '压差(Pa)',
      value: 'sourcePressure',
    },
  ],
  gasConcentrationConfig: {
    type: 'line_smooth', // 使用光滑曲线类型
    legend: { show: true },
    xAxis: [
      {
        show: true,
        name: '时间',
        axisLabel: { color: '#000000' },
      },
    ],
    yAxis: [
      {
        show: true,
        name: '浓度(%)',
        position: 'left',
        splitLine: { show: false },
        axisLine: {
          show: true,
          lineStyle: { color: '#333' },
        },
        axisLabel: { color: '#000000' },
        nameTextStyle: { color: '#000' },
      },
    ],
    series: [
      {
        label: '氧气浓度',
        readFrom: 'chartData',
        xprop: 'readTime',
        yprop: 'o2Val',
      },
      {
        label: '一氧化碳浓度',
        readFrom: 'chartData',
        xprop: 'readTime',
        yprop: 'coVal',
      },
      {
        label: '二氧化碳浓度',
        readFrom: 'chartData',
        xprop: 'readTime',
        yprop: 'co2Val',
      },
    ],
    readFrom: '',
  },
  pressureConfig: {
    type: 'line', // 使用普通折线图类型
    legend: { show: true },
    xAxis: [
      {
        show: true,
        name: '时间',
        axisLabel: { color: '#000000' },
      },
    ],
    yAxis: [
      {
        show: true,
        position: 'left',
        name: '压力(kPa)',
        axisLabel: { color: '#000000' },
      },
    ],
    series: [
      {
        label: '压差',
        readFrom: 'chartData',
        xprop: 'readTime',
        yprop: 'sourcePressure',
      },
    ],
    readFrom: '',
  },
};

// 历史数据相关
export const historicalColumns: BasicColumn[] = [
  // {
  //   title: '序号',
  //   dataIndex: 'orderNo',
  //   width: 60,
  // },
  // {
  //   title: '区域',
  //   dataIndex: 'enforcement',
  //   width: 100,
  // },
  {
    title: '煤矿名称',
    dataIndex: 'mineName',
    width: 200,
  },
  {
    title: '密闭名称',
    dataIndex: 'devicePos',
    width: 100,
  },
  {
    title: '所属煤层',
    dataIndex: 'coalSeamName',
    width: 100,
  },
  {
    title: 'CO(ppm)',
    dataIndex: 'coVal',
    width: 100,
  },
  {
    title: 'CO2(%)',
    dataIndex: 'co2Val',
    width: 100,
  },
  {
    title: 'CH4(%)',
    dataIndex: 'ch4Val',
    width: 100,
  },
  {
    title: 'C2H2(ppm)',
    dataIndex: 'c2h2Val',
    width: 100,
  },
  {
    title: 'C2H4(%)',
    dataIndex: 'c2h4Val',
    width: 100,
  },
  {
    title: 'O2(%)',
    dataIndex: 'o2Val',
    width: 100,
  },
  {
    title: '温度(℃)',
    dataIndex: 'temperature',
    width: 100,
  },
  {
    title: '压差(Pa)',
    dataIndex: 'sourcePressure',
    width: 100,
  },
  // {
  //   title: '爆炸危险性',
  //   dataIndex: 'explosionHazard',
  //   width: 100,
  // },
  {
    title: '更新时间',
    dataIndex: 'createTime',
    width: 100,
  },
];

export const historicalFormSchema: FormSchema[] = [
  {
    field: 'mineCode',
    label: '煤矿名称',
    component: 'MineCascader',
    slot: 'mine-cascader',
    colProps: { span: 6 },
  },
  // {
  //   field: 'mineNameAbbr',
  //   label: '煤矿简称',
  //   component: 'Input',
  //   colProps: { span: 6 },
  // },
  // {
  //   field: 'productStatus',
  //   label: '生产状态',
  //   component: 'Select',
  //   componentProps: {
  //     options: [
  //       { label: '拟建矿井', value: '0' },
  //       { label: '正常生产矿井', value: '1' },
  //       { label: '长期停产矿井', value: '1' },
  //     ],
  //   },
  //   colProps: { span: 6 },
  // },
  // {
  //   field: 'riskLevel',
  //   label: '自燃情况',
  //   component: 'Select',
  //   componentProps: {
  //     options: [
  //       { label: 'Ⅰ类容易自燃', value: '0' },
  //       { label: 'Ⅱ类自燃', value: '1' },
  //       { label: 'Ⅲ类不易自燃', value: '2' },
  //     ],
  //   },
  //   colProps: { span: 6 },
  // },
  // {
  //   field: 'coalSeam',
  //   label: '所属煤层',
  //   component: 'Select',
  //   componentProps: {
  //     options: [
  //       { label: '煤层1', value: '0' },
  //       { label: '煤层2', value: '1' },
  //       { label: '煤层3', value: '2' },
  //     ],
  //   },
  //   colProps: { span: 6 },
  // },
  {
    field: 'goafId',
    label: '密闭名称',
    component: 'ApiSelect',
    slot: 'goaf-select',
    colProps: { span: 6 },
  },
  {
    field: 'startTime',
    label: '起始日期',
    component: 'DatePicker',
    componentProps: {
      //日期格式化，页面上显示的值
      format: 'YYYY-MM-DD hh:mm:ss',
      //返回值格式化（绑定值的格式）
      valueFormat: 'YYYY-MM-DD hh:mm:ss',
    },
    defaultValue: dayjs().add(-7, 'day').format('YYYY-MM-DD hh:mm:ss'),
    colProps: { span: 6 },
  },
  {
    field: 'endTime',
    label: '结束日期',
    component: 'DatePicker',
    componentProps: {
      //日期格式化，页面上显示的值
      format: 'YYYY-MM-DD hh:mm:ss',
      //返回值格式化（绑定值的格式）
      valueFormat: 'YYYY-MM-DD hh:mm:ss',
    },
    defaultValue: dayjs().format('YYYY-MM-DD hh:mm:ss'),
    colProps: { span: 6 },
  },
];

export const treeData: TreeItem[] = [
  {
    title: '气体参数 ',
    key: '0-0',
    children: [
      { title: 'CO', key: '0-0-0' },
      { title: 'CH4', key: '0-0-1' },
      { title: 'C2H4', key: '0-0-2' },
      { title: 'C2H2', key: '0-0-3' },
      { title: 'CO2', key: '0-0-4' },
      { title: 'O2', key: '0-0-5' },
    ],
  },
  {
    title: '内外压力及压差',
    key: '1-1',
    children: [
      { title: '内压力', key: '1-1-0' },
      { title: '外压力', key: '1-1-1' },
      { title: '压差', key: '1-1-2' },
    ],
  },
  {
    title: '温度',
    key: '2-2',
  },
];

function getTagType(level: string) {
  switch (level) {
    case '1':
      return 'red';
    case '2':
      return 'volcano';
    case '3':
      return 'orange';
    case '4':
      return 'success';
    default:
      return 'default';
  }
}
export function tagCellRender(record: any) {
  if (!record) return h(Tag, { bordered: false, color: 'default' }, '-');
  return h(Tag, { bordered: false, color: getTagType(record.alarmLevel) }, record.alarmName);
}
