export type ScalarType = boolean | number | string | Date | null | undefined;
export type When =
  | (Record<string, ScalarType | ScalarType[]> | "*")
  | ((record: Record<string, ScalarType>) => boolean);
export type ModelConfig = {
  metadata: {
    nameKeys: string[];
    pageActions?: PageActions;
  };
  table: {
    toolbar: {
      searchBar: {
        fields: string[];
        containsFields?: string[];
        placeholder?: string;
      };
      actions: (
        | {
            action: "SETTING";
            desc?: string;
            option?: any;
          }
        | {
            action: "REFRESH";
            desc?: string;
          }
        | {
            action: "EXPORT";
            desc?: string;
            fields?: string[];
          }
      )[];
    };
    header: {
      filter: string[];
      sorter: (
        | string
        | { field: string; order?: "asc" | "desc"; default?: true }
      )[];
    };
    fields: string[];
    rowSelection: {
      actions: (
        | {
            action: "INSERT";
            desc: string;
          }
        | {
            action: "DELETE";
            desc: string;
          }
        | {
            action: "EXPORT";
            desc: string;
            fields?: string[];
          }
        | {
            action: "CHANGE_STATUS";
            desc: string;
            values: Record<string, ScalarType>;
          }
        | {
            action: "JUMP";
            desc: string;
            url: string;
          }
      )[];
    };
    rowActions: {
      actions: (
        | {
            action: "EDIT";
            desc: string;
            when?: When;
          }
        | {
            action: "DETAIL";
            desc: string;
            when?: When;
          }
        | {
            action: "DELETE";
            desc: string;
            when?: When;
          }
        | {
            action: "CHANGE_STATUS";
            desc: string;
            values: Record<string, ScalarType>;
            when?: When;
          }
        | {
            action: "JUMP";
            desc: string;
            url: string;
            when?: When;
          }
      )[];
      visibleNum: number;
    };
    params: {
      pageSize: number;
      [k: string]: ScalarType;
    };
  };
  form: {
    fields: string[];
    initialValues?: Record<string, ScalarType>;
    reaction?: {
      [name: string]: {
        toggle: {
          props: {
            value?: string;
            readonly?: boolean;
            hidden?: boolean;
            required?: boolean;
          };
          when: Record<string, any>;
        }[];
        defaultProps: {
          readonly?: boolean;
          hidden?: boolean;
          value?: string;
          required?: boolean;
        };
      };
    };
  };
  show: {
    fields: string[];
  };
};
export interface IModelsConfig {
  [k: string]: ModelConfig;
}
export type PageActions = {
  hasDetailPage?: boolean;
  editOnNewPage?: boolean;
  detailOnNewPage?: boolean;
  createOnNewPage?: boolean;
};
