import { ComponentType } from './index';
import type { CSSProperties } from 'vue';
// import type { ElCol, ElButton } from 'element-plus';
import type { ColProps } from 'element-plus/es/components/col/src/col';
import type { ButtonProps } from 'element-plus/es/components/button/src/button';

export interface RenderReturnParams {
  schema: FormSchema;
  values: Recordable;
  model: Recordable;
  field: string;
}

export interface componentProps {
  options?: any[];
  placeholder?: string;
  showButton?: boolean;
  onInput?: () => Recordable;
  onChange?: () => Recordable;
}

export interface FormSchema {
  field: string;
  label?: string;
  type?:string;
  labelMessage?: string;
  labelMessageStyle?: CSSProperties;
  defaultValue?: any;
  component?: ComponentType;
  componentProps?: any;
  slot?: string;
  rules?: object | object[];
  rowProps?: ColProps;
  colProps?: ColProps;
  isFull?: boolean;
  suffix?: string;
  showFeedback?: boolean;
  showLabel?: boolean;
  requireMarkPlacement?: string;
  hidden?: boolean | ((renderCallbackParams: RenderReturnParams) => boolean);
}

export interface FormProps {
  model?: Recordable;
  labelWidth?: number | string;
  schemas?: FormSchema[];
  inline: boolean;
  layout?: string;
  size: string;
  labelPlacement: string;
  isFull: boolean;
  showActionButtonGroup?: boolean;
  showResetButton?: boolean;
  resetButtonOptions?: Partial<ButtonProps>;
  showSubmitButton?: boolean;
  showAdvancedButton?: boolean;
  submitButtonOptions?: Partial<ButtonProps>;
  submitButtonText?: string;
  resetButtonText?: string;
  rowProps?: ColProps;
  colProps?: ColProps;
  resetFunc?: () => Promise<void>;
  submitFunc?: () => Promise<void>;
  submitOnReset?: boolean;
  baseGridStyle?: CSSProperties;
  draggable?: boolean;
  collapsed?: boolean;
  collapsedRows?: number;
}

export interface FormActionType {
  submit: () => Promise<any>;
  setProps: (formProps: Partial<FormProps>) => Promise<void>;
  setSchema: (schemaProps: Partial<FormSchema[]>) => Promise<void>;
  setFieldsValue: (values: Recordable) => void;
  clearValidate: (name?: string | string[]) => Promise<void>;
  getFieldsValue: () => Recordable;
  resetFields: () => Promise<void>;
  validate: (nameList?: any[]) => Promise<any>;
  setLoadingSub: (status: boolean) => void;
}

export type RegisterFn = (formInstance: FormActionType) => void;

export type UseFormReturnType = [RegisterFn, FormActionType];
