import {
  SystemRole,
  SystemRoleAttribute,
  TransactionType,
} from '@/utils/role.util';
import { TreeSelectionKeys } from 'primevue/tree';

export interface SelectTreeDialogProps {
  visible?: boolean;
  type?: 'Group' | 'Category';
  /**
   * Specify wether the all tree node should be auto checked once it rendered.
   * @default false
   */
  autoSelectAll?: boolean;
  /**
   * Set custom query params for group tree.
   *
   * By default, query params has been determined by the path
   */
  groupParams?: TreeQueryParams;
  header?: string;
  subHeader?: string;
  selectionMode?: 'single' | 'checkbox';
  /**
   * For checkbox selection, current behavior is preventing select if there is no node selected.
   *
   * @default true
   */
  allowEmptySelection?: boolean;
  /**
   * The previously selected tree key to be displayed again.
   */
  keys?: string[];
  /**
   * The lists to be displayed in the dialog.
   */
  lists?: (string | object)[];
  /**
   * The label of the list if your list item is an object.
   * Choose a property from the item to be displayed on the list.
   */
  listLabel?: string;
  /**
   * Disable node 'All' selection
   */
  disableNodeAll?: boolean;
  disableKeys?: number[];
  exactDisableKey?: number;
  /**
   * Defines the tree is readonly and disabled.
   */
  readonly?: boolean;
  /**
   * Defines the group tree to showing disposable groups.
   */
  showDisposableGroups?: boolean;
  /**
   * The asset quantity already used, to validate the chosen group's available quota.
   */
  validateQuota?: { assetQuantity: number };
  /**
   * Defines the tree to be flattened and shows disposable only
   */
  flattenDisposableNode?: boolean;
  /**
   * Defines the group tree to disable excluded keys
   */
  excludedKeys?: string[];
  /**
   * Render hidden dialog to trigger fetch tree
   */
  hidden?: boolean;
  /**
   * Disable level 2 (All > Level 1 > Level 2)
   */
  disableSubChildren?: boolean;
  /**
   * Specifies the required manager transaction permission to make a node selectable.
   * If the node's `manager[transaction]` value is false, the node will be rendered in a disabled state.
   */
  requiredManagerPermission?: TransactionType;
  /**
   * Specifies the required system role permission to make a node selectable.
   * If the node's `SystemRoleAttribute[SystemRole]` value is false, the node will be rendered in a disabled state.
   */
  requiredSystemRole?: [SystemRoleAttribute, keyof SystemRole];
}

type TreeSelectPayload = {
  keys: TreeSelectionKeys | undefined;
  selectedNodes: TreeNode[] | undefined;
  singleNode: TreeNode | undefined;
};

export type SelectTreeDialogEmits = {
  'update:visible': [state: boolean];
  'select': [keys?: TreeSelectPayload];
  'hide': [];
};

export interface SelectTreeDialogSlots {
  description: VNode[];
}

/**
 * **TSVue v2 - SelectTreeDialog**
 *
 * --- ---
 * ![TSVue](https://ik.imagekit.io/kurniadev/TS-HEAD-BLACK.png)
 *
 * @group components
 */
declare class SelectTreeDialog extends ClassComponent<
  SelectTreeDialogProps,
  SelectTreeDialogSlots,
  SelectTreeDialogEmits
> {}

declare module '@vue/runtime-core' {
  interface GlobalComponents {
    SelectTreeDialog: GlobalComponentConstructor<SelectTreeDialog>;
  }
}

export default SelectTreeDialog;
