import type { ExtractPropTypes, PropType } from 'vue'
import type { Filter, Formatter } from './utils'
import type { PickerOption } from 'vant/lib/picker/types'

const currentYear = new Date().getFullYear()
export type DateTimePickerColumnType = 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'

export const horDateTimePickerProps = {
  modelValue: {
    type: [Array, String, Date] as PropType<string[] | string | Date>,
    default: [],
  },
  filter: {
    type: Function as PropType<Filter>,
  },
  formatter: {
    type: Function as PropType<Formatter>,
    default: (type: string, val: PickerOption) => {
      if (type === 'year') {
        val.text += '年'
      }
      if (type === 'month') {
        val.text += '月'
      }
      if (type === 'day') {
        val.text += '日'
      }
      if (type === 'hour') {
        val.text += '时'
      }
      if (type === 'minute') {
        val.text += '分'
      }
      if (type === 'second') {
        val.text += '秒'
      }
      return val
    },
  },
  columnsType: {
    type: Array as PropType<DateTimePickerColumnType[]>,
    default: () => ['year', 'month', 'day', 'hour', 'minute', 'second'],
  },
  minDate: {
    type: Date,
    default: () => new Date(currentYear - 10, 0, 1, 0, 0),
  },
  maxDate: {
    type: Date,
    default: () => new Date(currentYear + 10, 11, 31, 23, 59),
  },
  valueFormat: {
    type: String,
    default: 'yyyy/MM/dd hh:mm:ss',
  },
}

export type HorDateTimePickerProps = ExtractPropTypes<typeof horDateTimePickerProps>
