import type { PropType } from 'vue';

export type IFormPattern = 'applying' | 'design' | 'view';

export type IFormUrl = {
  images?: string;
  imageupload?: string;
};

export type IFormEnuable = {
  applying?: {
    'paste-data'?: boolean;
    'event-select-cells'?: boolean;
  };
};

export type IFormCell = {
  colspan?: number;
  rowspan?: number;
  x?: number;
  y?: number;
  'border-color'?: { [key: string]: any };
  'border-style'?: { [key: string]: any };
  'oblique-line'?: string;
  [key: string]: any;
};

export type IFormColumn = {
  width?: number | string;
  x?: number;
  y?: number;
  [key: string]: any;
};
export type IFormDataSet = {
  data?: Array<any>;
  template?: { [key: string]: any };
};

export type IFormRow = {
  height?: number | string;
  x?: number;
  y?: number;
  [key: string]: any;
};

export type IFormTable = {
  width?: number | string;
  height?: number | string;
  rows?: number;
  columns?: number;
  className?: string;
  'border-style'?: string;
  'border-color'?: string;
  paging?: boolean | { [key: string]: any };
  center?: boolean;
  'print-size'?: string;
  x?: number;
  y?: number;
  [key: string]: any;
};

export type IFormData = {
  cell?: Array<IFormCell>;
  columns?: Array<IFormColumn>;
  controls?: Array<any>;
  datasets?: IFormDataSet;
  rows?: Array<IFormRow>;
  table?: IFormTable;
  verified?: boolean;
};

export type ISysStemInfo = {
  applicantDepartment: { text: string; value: string }; // 申请人部门
  applicantName?: { text: string; value: string }; // 申请人名称
  applicantPhoneNumber?: string; // 申请人手机号
  applicationDate?: string; // 申请日期
  processId?: string; // 流程id
  processSteps?: string; // 流程步骤
  formNumber?: string; // 表单编号
};

export interface ICustomFormProps {
  url?: IFormUrl;
  pattern?: IFormPattern;
  data?: IFormData;
  paging?: boolean;
  height?: number | string;
  enuable?: IFormEnuable;
  toolbox?: { [key: string]: any };
  control?: { [key: string]: any };
  menu?: {
    // order 配置设计模式菜单栏显示按钮
    order?: [string[]];
    // 用于判断 order 是追加还是整体替换
    type?: 'concat' | 'replace';
    // 用于覆盖按钮数据，目前用于版本号选中项及下拉数据替换
    controls?: Record<string, any>;
  };
  isInit?: boolean;
  readonly?: boolean;
  language?: string;
  timezone?: number;
  systemInfo?: ISysStemInfo;
  [key: string]: any;
  // events?: { [key: string]: (...params: any[]) => any };
}

export const CustomFormProps = {
  url: {
    type: Object as PropType<IFormUrl>,
    default: undefined,
  },
  pattern: {
    type: String as PropType<IFormPattern>,
    default: 'design',
  },
  data: {
    type: Object as PropType<IFormData>,
    default: undefined,
  },
  paging: {
    type: Boolean as PropType<boolean>,
    default: undefined,
  },
  height: {
    type: Number as PropType<number>,
    default: undefined,
  },
  enuable: {
    type: Object as PropType<IFormEnuable>,
    default: undefined,
  },
  toolbox: {
    type: Object,
    default: undefined,
  },
  control: {
    type: Object,
    default: undefined,
  },
  isInit: {
    type: Boolean,
    default: false,
  },
  readonly: {
    type: Boolean,
    default: false,
  },
  language: {
    type: String,
    default: 'zh-CN',
  },
  timezone: {
    type: Number,
    default: 8,
  },
  systemInfo: {
    type: Object as PropType<ISysStemInfo>,
    default: undefined,
  },
  menu: {
    type: Object as PropType<ICustomFormProps['menu']>,
    default: {},
  },
  designSave: {
    type: Function,
    default: undefined,
  },
  // events: {
  //   type: Object,
  //   default: undefined,
  // },
};

export interface ICustomFormMethod {
  init?: () => void;
  loadData?: (data: IFormData) => void;
  getData?: () => IFormData;
  check?: () => boolean;
}
