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> {
    /**
     * 获取时间
     * @returns 时间
     */
    getTime: () => Dayjs[]
    /**
     * 设置时间
     * @param time 时间
     */
    setTime: (time: Dayjs[]) => void
    /**
     * 获取选中的选项
     * @returns 选中的选项
     */
    getCheckedOption: () => TimeBarLabel['options'][0]
    /**
     * 设置选中的选项
     * @param index 选项索引
     */
    setCheckedOption: (index: number) => void
    /**
     * 获取时间栏的值
     * @returns 时间栏的值
     */
    getTimeBarValue: () => TimeBarChangeEvent
}
