import type { MaybeRefOrGetter } from 'vue'
import type { BtnOptions, ThemeType } from '../types'
import type { BglFormSchemaT } from '../types/BagelForm'

export interface ModalOptions {
	title?: string
	dismissable?: boolean
	side?: boolean
	width?: string
	actions?: BtnOptions[]
	class?: string
	visible?: boolean
	zIndex?: number
}

export interface ModalConfirmOptions {
	'title': string
	'message': string
	'confirmText'?: string
	'confirmBtnColor'?: ThemeType
	'cancelText'?: string
	'cancelBtnColor'?: ThemeType
	'resolve': (val: boolean) => void
	'onUpdate:visible': () => void
	'visible': boolean
}

export type ModalType = 'modal' | 'modalForm' | 'confirmModal'
export type ConfirmModalUserOptions = string | {
	title: string
	message: string
	confirmText?: string
	cancelText?: string
	confirmBtnColor?: string
	cancelBtnColor?: string
}

export interface ModalComponentProps<T extends { [key: string]: any }> {
	componentSlots: { [key: string]: any }
	modalType: ModalType
	modalOptions: ModalOptions | ModalFormOptions<T> | ModalConfirmOptions
}

export interface ModalFormComponentProps<T extends { [key: string]: any }> extends ModalComponentProps<T> {
	modalType: 'modalForm'
	modalOptions: ModalFormOptions<T>
}

export interface ModalFormOptions<T> extends ModalOptions {
	'schema': MaybeRefOrGetter<BglFormSchemaT<T>>
	'modelValue'?: T
	'onUpdate:modelValue'?: (val: T) => void
	'onSubmit'?: (formData: T) => any
	'onDelete'?: (formData: T) => Promise<void>
	'onDuplicate'?: (formData: T) => Promise<void>
	'submitText'?: string
	'cancelText'?: string
	'deleteText'?: string
	'duplicateText'?: string
	'onError'?: (err: any) => void
}
