import {
    FormProps,
    RangePicker,
    Input,
    InputNumber,
    Textarea,
    InputPassword,
    RadioGroup,
    Select,
    TreeSelect,
    Cascader,
    CheckboxGroup,
    DatePicker,
    FormItem, TimeRangePicker, TimePicker,
} from "ant-design-vue";
import {Ref, UnwrapRef, VNode} from "vue";
import {ComponentProps} from "vue-component-type-helpers";

type FormProMaxItemType =
    | 'custom'
    | 'input'
    | 'inputPassword'
    | 'inputNumber'
    | 'inputTextArea'
    | 'radioGroup'
    | 'select'
    | 'selectIcon'
    | 'selectUser'
    | 'treeSelect'
    | 'cascader'
    | 'checkboxGroup'
    | 'datePicker'
    | 'rangePicker'
    | 'timeRangePicker'
    | 'timePicker'
    | 'administrativeDivisionsTree';

interface FormProMaxItemCommonProps extends ComponentProps<typeof FormItem> {
    label?: string,
    grid?: Grid,
    placeholder?: string,
    remarkRender?: () => VNode | string,
    customRender?: () => VNode;
    options?: (SelectNodeVo<unknown> | TreeNodeVo<unknown>) [] | Ref<(SelectNodeVo<unknown> | TreeNodeVo<unknown>)[]>
}

export interface FormProMaxItemProps<T extends FormProMaxItemType = any, C = any> extends FormProMaxItemCommonProps {
    type: T
    componentsProps?: C
}

export type FormProMaxItemOptions<T> = {
    [key in keyof T | string]:
    FormProMaxItemProps<'custom', ComponentProps<Record<string, any>>>
    | FormProMaxItemProps<'input', ComponentProps<typeof Input>>
    | FormProMaxItemProps<'inputPassword', ComponentProps<typeof InputPassword>>
    | FormProMaxItemProps<'inputNumber', ComponentProps<typeof InputNumber>>
    | FormProMaxItemProps<'inputTextArea', ComponentProps<typeof Textarea>>
    | FormProMaxItemProps<'radioGroup', ComponentProps<typeof RadioGroup>>
    | FormProMaxItemProps<'select', ComponentProps<typeof Select>>
    | FormProMaxItemProps<'treeSelect', ComponentProps<typeof TreeSelect>>
    | FormProMaxItemProps<'cascader', ComponentProps<typeof Cascader>>
    | FormProMaxItemProps<'checkboxGroup', ComponentProps<typeof CheckboxGroup>>
    | FormProMaxItemProps<'datePicker', ComponentProps<typeof DatePicker>>
    | FormProMaxItemProps<'rangePicker', ComponentProps<typeof RangePicker>>
    | FormProMaxItemProps<'timeRangePicker', ComponentProps<typeof TimeRangePicker>>
    | FormProMaxItemProps<'timePicker', ComponentProps<typeof TimePicker>>
    | FormProMaxItemProps<'administrativeDivisionsTree', ComponentProps<Record<string, any>>>
}

export interface FormProMaxProps<T = {}> extends FormProps {
    grid?: Grid
    gutter?: number;
    formItemOptions?: FormProMaxItemOptions<T> | Ref<FormProMaxItemOptions<T>> | UnwrapRef<FormProMaxItemOptions<T>>
}
