import TyComponent from '../common/component'

const currentYear = new Date().getFullYear()
TyComponent({
  /**
   * 组件的属性列表
   */
  properties: {

    value: {
      type: [String, Number]
    },
    type: {
      type: String,
      value: 'datatime'
    },
    minDate: {
      type: Number,
      value: new Date(currentYear - 10, 0, 1).getTime()
    },
    maxDate: {
      type: Number,
      value: new Date(currentYear + 10, 11, 31).getTime()
    },
    minHour: {
      type: Number,
      value: 0
    },
    maxHour: {
      type: Number,
      value: 23
    },
    minMinute: {
      type: Number,
      value: 0
    },
    maxMinute: {
      type: Number,
      value: 59
    },
    filter: {
      type: Function,
      value: (type, values) => values
    },
    formatter: {
      type: Function,
      value: (type, value) => value
    },
    title: {
      type: String
    },
    showToolbar: {
      type: Boolean,
      value: true
    },
    loading: {
      type: Boolean,
      value: false
    },
    itemHeight: {
      type: Number,
      value: 44
    },
    confirmButtonText: {
      type: String,
      value: '确认'
    },
    cancelButtonText: {
      type: String,
      value: '取消'
    },
    visibleItemCount: {
      type: Number,
      value: 5
    },
    activeClass: {
      type: String
    },
    toolbarClass: {
      type: String
    },
    columnClass: {
      type: String
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleInput({detail}) {
      if (this.data.type === 'time' && typeof detail === 'number') return
      this.triggerEvent('input', detail)
    },
    handleChange({detail}) {
      this.triggerEvent('change', detail)
    },
    handleConfirm({detail}) {
      this.triggerEvent('confirm', detail)
    },
    handleCancel({detail}) {
      this.triggerEvent('cancel', detail)
    }
  }
})
