import { ElementUIComponent } from 'element-ui/types/component'
import { ElInputNumber } from 'element-ui/types/input-number'
import { VNodeData } from 'vue'
import { ElTableColumn } from 'element-ui/types/table-column'
import moment from 'moment'

export const gisNames = ['spectrum', 'pipelineDefect', 'OnlineImport']

export const pageSizes = [10, 20, 30, 50, 100, 1000]

export const getDefaultPagination = () => ({ current: 1, size: 30 })

export const getIntervalValue = (start: string | number, end: string | number, infinitySign: string = '∞') =>
  !start && !end ? infinitySign : `${start || 0} ~ ${end || infinitySign}`

export const telAndMobileReg = () => /(^(0\d{2,3}-?)?\d{7,8}$)|(^1[3-9]\d{9}$)/

export const disabledMenus = ['', 'project']

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

export const getDefalutNumberProp = (
  prop: Partial<Omit<ElInputNumber, keyof ElementUIComponent>> & {
    style?: VNodeData['style']
    class?: VNodeData['class']
  } = {}
) => ({
  min: 0,
  max: 9999999,
  size: 'small',
  precision: 0,
  style: { width: '100%', textAlign: 'left' },
  class: 'input-number',
  clearable: true,
  ...prop
})

export const getDefaultDateTimePickerProp = () => {
  return {
    shortcuts: [
      {
        text: '最近一周',
        onClick(picker) {
          const end = moment().endOf('day').toDate()
          const start = moment().startOf('day').add(-7, 'days').toDate()
          picker.$emit('pick', [start, end])
        }
      },
      {
        text: '最近一个月',
        onClick(picker) {
          const end = moment().endOf('day').toDate()
          const start = moment().startOf('day').add(-1, 'months').toDate()
          picker.$emit('pick', [start, end])
        }
      },
      {
        text: '最近三个月',
        onClick(picker) {
          const end = moment().endOf('day').toDate()
          const start = moment().startOf('day').add(-3, 'months').toDate()
          picker.$emit('pick', [start, end])
        }
      },
      {
        text: '最近一年',
        onClick(picker) {
          const end = moment().endOf('day').toDate()
          const start = moment().startOf('day').add(-12, 'months').toDate()
          picker.$emit('pick', [start, end])
        }
      }
    ]
  }
}

export const rgb2Hex = (color: string) => {
  const [r, g, b] = (color || '').replace(/rgba?|\(|\)/g, '').split(',')
  const toHex = (num: number | string) => {
    const hex = Number(num).toString(16)
    return `${hex.length === 1 ? '0' : ''}${hex}`
  }
  return `#${toHex(r)}${toHex(g)}${toHex(b)}`
}

export const drainageTypeKey = { codeKey: 'outfall_type', codeRemark: '排水类型' }
export const drainageTypeKeyDefaultValues = [
  { codeValue: 'ys', notes: '雨水', sort: 0 },
  { codeValue: 'ws', notes: '污水', sort: 1 },
  { codeValue: 'ysws', notes: '雨污合流', sort: 2 }
]
