import type { Dayjs } from 'dayjs'
import type { BasicWidgetInstance, BasicWidgetProps } from '../../utils'

/**
 * 对应 first-ui datePicker 组件 type 参数
 */
type FirstUIDatePickerType = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8

export interface TimeBarChangeEvent {
    value: Dayjs[]
    option?: TimeBarLabel['options'][0]
}

export interface TimeBarLabel {
    text?: string
    breforeIcon?: boolean
    afterIcon?: boolean
    options?: {
        text?: string
        value?: string
        checked?: boolean
        format?: string
        timeType?: FirstUIDatePickerType
    }[]
    onClick?: () => void
    onChange?: (e: TimeBarChangeEvent) => void
}

export interface TimeBarTime {
    type: 'single' | 'range'
    timeType: FirstUIDatePickerType
    format?: string
    value?: Dayjs[]
    onChange?: (e: TimeBarChangeEvent) => void
}

export interface TimeBarButton {
    /**
     * 图标，仅支持 fui-icon name
     */
    icon?: string
    label: string
    onClick?: (e: { index: number; label: string }, time: TimeBarChangeEvent) => void
}

export interface TimeBarProps extends BasicWidgetProps {
    // 是否只读
    readonly?: boolean
    // 对齐方式
    align?: 'left' | 'center' | 'right'
    // 标题
    label?: TimeBarLabel
    // 时间
    time: TimeBarTime
    // 扩展按钮
    buttons?: TimeBarButton[]
}

export interface TimeBarInstance extends BasicWidgetInstance<TimeBarProps> {
    getTime: () => Dayjs[]
    setTime: (time: Dayjs[]) => void
    getCheckedOption: () => TimeBarLabel['options'][0]
    setCheckedOption: (index: number) => void
    getTimeBarValue: () => TimeBarChangeEvent
}
