import { PropType, ExtractPropTypes } from "vue";
import PageContent from "./page-content";

/***
 * @param title 标题
 * @param apis 请求
 * @param columns 列数据
 * @param notReuqiredInit 首次加载是否需要请求列表
 * @param notPagination 不需要分页器
 * @param mockData 模拟数据
 * @param isTree 是否为tree
 * @param powers 功能权限
 * @param treeProps
 */
export interface ContentConfig {
  permissions: string[],
  statusListProp?:string
  superForceAction?: boolean
  title: string;
  transformCompany?: boolean;
  maxHeight?: string;
  showTitle?: boolean;
  apis: ContentApis | any;
  columns: any;
  notReuqiredInit?: boolean;
  notPagination?: boolean;
  notPreview?: boolean;
  statusProp?: string;
  deleteProp?: any;
  mockData?: Array<any>;
  isTree?: boolean;
  treeProps?: any;
  rowKey?: string;
  payProps?: Record<string, string>;
  returnProps?: Record<string, string>;
  delTooltip?: string;
  inv?: boolean;
  isRequesetArray?: boolean;
  openStatus?: string;
  stopStatus?: string;
  notNeedCompanyFilter?: boolean;
  companyProp?: string;
  superUserNoAction?: boolean;
  superUserNoPerview?: boolean;
  listNoRelation?: boolean;
  showCreate?: (isSuperUser: boolean) => boolean;
  showStatus?: (isSuperUser) => boolean;
  statusRowProp?: (row: any) => any;
  showPreview?: (row: Record<string, string>) => boolean;
  showDelete?: (row: Record<string, string>) => boolean;
  showExpand?: (row: Record<string, string>) => boolean;
  showPayTagFn?: (row: Record<string, string>, permissions: any[]) => boolean;
  showUnPayTagFn?: (row: Record<string, string>, permissions: any[]) => boolean;
  showUnReturnTagFn?: (row: Record<string, string>, permissions: any[]) => boolean;
  handleData?: (data: any, parmas: any) => any;
  tableRowClassName?:(...rest:any[]) => any;
  showReturnTagFn?: (
    row: Record<string, string>,
    permissions: any[]
  ) => boolean;
}

interface ContentApiResponse {
  code: number;
  message: string;
  data: any;
}

type API = (data: any) => Promise<ContentApiResponse>;

export type ActionType = "update" | "delete" | "create" | "preview" | "status";

export interface ContentApis {
  httpAdd?: API;
  httpList: API;
  httpDelete?: API;
  httpUpdate?: API;
  httpStatus?: API;
}

export type PageContentInstance = typeof PageContent & {
  onBeforeAction: (type: ActionType, data?: any, responseCallback?: () => void) => void;
  getPageData: (params?: any) => void;
  onSearch: () => void;
};

export const pageContentProps = {
  contentConfig: {
    type: Object as PropType<ContentConfig>,
    required: true
  },
  onGetReuslt: {
    type: Function
  },
  onGetHandleResult: {
    type: Function
  },
  pageSize: {
    type: Number,
    default: 15
  },
  powers: {
    type: Array as PropType<string[]>,
    default: () => []
  },
  otherSearchParameter: {
    type: Object,
    default: () => ({})
  }
} as const;

export const actionProps = {
  config: {
    type: Object as PropType<{ api: API }>
  },
  isRequesetArray: {
    type: Boolean
  },
  statusConfig: {
    type: Object
  }
};

export type PageContentProps = ExtractPropTypes<typeof pageContentProps>;
