import { getIntervalValue } from '@/utils/constant'
import { ElTableColumn } from 'element-ui/types/table-column'
import moment from 'moment'
import { ColItem, IDeviceTypeParam, IPoint, IStandardParam, ITeam } from './api/common'

export const alignLeft = (tooltips: boolean = true): Partial<ElTableColumn> => ({
  align: 'left',
  headerAlign: 'left',
  showOverflowTooltip: tooltips
})

export const deviceTypeCols: ColItem[] = [
  { type: 'selection', width: '50px' },
  { type: 'index', label: '序号', width: '60px' },
  { prop: 'deviceTypeName', label: '设备类型', minWidth: '120px', ...alignLeft() },
  { prop: 'dataUploadTime', label: '数据刷新时间(min)', width: '140px' },
  { prop: 'icon', label: '图标', width: '100px', _slot: true }
]

export const deviceTypeParamCols: ColItem[] = [
  { type: 'selection', width: '50px' },
  { type: 'index', label: '序号', width: '60px' },
  { prop: 'targetName', label: '参数名称', minWidth: '120px', ...alignLeft() },
  { prop: 'targetCode', label: '字段名称', minWidth: '120px', ...alignLeft() },
  { prop: 'targetUnit', label: '单位', minWidth: '120px', ...alignLeft() },
  {
    prop: 'range',
    label: '量程',
    minWidth: '120px',
    ...alignLeft(),
    formatter: ({ targetMin, targetMax }: IDeviceTypeParam) => getIntervalValue(targetMin, targetMax)
  },
  {
    prop: 'isshow',
    label: '是否显示',
    width: '80px',
    _slot: true
  }
]

export const standardCols: ColItem[] = [
  { type: 'selection', width: '50px' },
  { type: 'index', label: '序号', width: '60px' },
  { prop: 'standardName', label: '指标标准名称', minWidth: '120px', ...alignLeft() },
  { prop: 'typeName', label: '设备类型', minWidth: '120px', ...alignLeft() },
  { prop: 'createUser', label: '创建人', minWidth: '120px', ...alignLeft() },
  { prop: 'createTime', label: '创建时间', width: '170px' }
]

export const standardParamCols: ColItem[] = [
  { type: 'selection', width: '50px' },
  { type: 'index', label: '序号', width: '60px' },
  { prop: 'targetName', label: '参数名称', minWidth: '120px', ...alignLeft() },
  { prop: 'targetUnit', label: '单位', width: '80px', ...alignLeft() },
  { prop: 'lowerLimit', label: '下限', width: '80px', ...alignLeft() },
  { prop: 'upperLimit', label: '上限', width: '80px', ...alignLeft() },
  {
    prop: 'timeRange',
    label: '有效时段',
    width: '120px',
    ...alignLeft(),
    formatter: ({ biginTime, endTime }: IStandardParam) => getIntervalValue(biginTime, endTime)
  },
  { prop: 'warningName', label: '预警级别', width: '120px', ...alignLeft() },
  { prop: 'istidings', label: '是否推送预警消息', width: '140px', _slot: true }
]

export const deviceCols: ColItem[] = [
  { type: 'selection', width: '50px' },
  { type: 'index', label: '序号', width: '60px' },
  { prop: 'deviceCode', label: '设备编码', width: '130px', ...alignLeft() },
  { prop: 'deviceSn', label: 'SN序列号', width: '120px', ...alignLeft() },
  { prop: 'deviceTypeName', label: '设备类型名称', width: '160px', ...alignLeft() },
  { prop: 'deviceModel', label: '设备型号', width: '120px', ...alignLeft() },
  { prop: 'deviceName', label: '设备名称', minWidth: '130px', ...alignLeft() },
  { prop: 'deviceFirm', label: '设备厂商', width: '110px', ...alignLeft() },
  { prop: 'firmLiaison', label: '厂商联系人', width: '100px', ...alignLeft() },
  { prop: 'liaisonPhone', label: '联系人电话', width: '120px', ...alignLeft() },
  { prop: 'buyTime', label: '采购时间', width: '110px', ...alignLeft() },
  { prop: 'deviceState', label: '设备状态', width: '80px', _slot: true },
  { prop: 'remark', label: '备注', width: '120px', ...alignLeft() }
]

export const teamCols: ColItem[] = [
  { type: 'selection', width: '50px' },
  { type: 'index', label: '序号', width: '60px' },
  { prop: 'groupByName', label: '监测分组名称', minWidth: '150px', ...alignLeft() },
  {
    prop: 'siteCount',
    label: '监测点(个)',
    width: '130px',
    ...alignLeft(),
    formatter: ({ siteIds }: ITeam) => (siteIds || []).length
  },
  { prop: 'remarks', label: '备注', minWidth: '130px', ...alignLeft() }
]

export const neighborCols: ColItem[] = [
  { type: 'selection', width: '50px' },
  { type: 'index', label: '序号', width: '60px' },
  { prop: 'siteName', label: '监测站点名称', minWidth: '150px', ...alignLeft() },
  { prop: 'deviceTypeName', label: '设备类型', minWidth: '130px', ...alignLeft() },
  { prop: 'upperSiteName', label: '上游监测站点名称', minWidth: '150px', ...alignLeft() },
  { prop: 'upperDeviceTypeName', label: '上游设备类型', minWidth: '130px', ...alignLeft() }
]

export const pointCols: ColItem[] = [
  { type: 'selection', width: '50px' },
  { type: 'index', label: '序号', width: '60px' },
  { prop: 'partitionName', label: '排水分区', minWidth: '100px', ...alignLeft() },
  { prop: 'groupByName', label: '监测分组', minWidth: '100px', ...alignLeft() },
  { prop: 'siteCode', label: '站点编码', minWidth: '130px', ...alignLeft() },
  { prop: 'siteName', label: '站点名称', minWidth: '130px', ...alignLeft() },
  { prop: 'deviceSn', label: '设备SN', minWidth: '100px', ...alignLeft() },
  { prop: 'deviceTypeName', label: '设备类型', minWidth: '100px', ...alignLeft() },
  { prop: 'deviceName', label: '设备名称', minWidth: '130px', ...alignLeft() },
  { prop: 'installPeople', label: '负责人', minWidth: '80px', ...alignLeft() },
  { prop: 'liaisonPhone', label: '联系方式', minWidth: '120px', ...alignLeft() },
  { prop: 'siteAddress', label: '安装地址', minWidth: '100px', ...alignLeft() },
  {
    prop: 'installTime',
    label: '安装时间',
    minWidth: '120px',
    ...alignLeft(),
    formatter: ({ installTime }: IPoint) => (installTime ? moment(installTime).format('YYYY-MM-DD') : '')
  },
  { prop: 'siteState', label: '站点状态', minWidth: '70px', _slot: true }
]
