import type Graphic from "../../../Graphic.js";
import type Column from "./Column.js";
import type { Icon } from "@esri/calcite-components/components/calcite-icon";

export type CellValue = null | undefined | string | number;

export type TextAlign = "start" | "center" | "end";

export type FeatureTableState = "disabled" | "loading" | "loaded" | "ready" | "error";

export type GridSupportedColumns = Column;

export type GridMultiSortPriority = "append" | "prepend";

export interface TableInteractionEvent {
  /** The feature associated with the cell. */
  feature?: Graphic;
  /** The field name associated with the cell. */
  fieldName?: string;
  /** Specifies the index of the row (not just the individual cell). */
  index?: number;
  /** The native event object used for the interaction. */
  native?: MouseEvent | PointerEvent | KeyboardEvent;
  /** The object ID of the feature associated with the cell. */
  objectId?: number;
}

export interface TableInteractionCellClickEvent extends TableInteractionEvent {
  /** The type of cell interaction event. */
  type: "cell-click";
}

export interface TableInteractionCellDblclickEvent extends TableInteractionEvent {
  /** The type of cell interaction event. */
  type: "cell-dblclick";
}

export interface TableInteractionCellPointeroverEvent extends TableInteractionEvent {
  /** The type of cell interaction event. */
  type: "cell-pointerover";
}

export interface TableInteractionCellPointeroutEvent extends TableInteractionEvent {
  /** The type of cell interaction event. */
  type: "cell-pointerout";
}

export interface TableInteractionCellKeydownEvent extends TableInteractionEvent {
  /** The type of cell interaction event. */
  type: "cell-keydown";
}

export interface TableInteractionColumnReorderEvent extends TableInteractionEvent {
  /** The type of table interaction event. */
  type: "column-reorder";
}

export type Direction = "asc" | "desc" | null | undefined;

export interface ColumnTableMenuConfig extends TableMenuConfig {
  /** The string value indicating the [icon](https://developers.arcgis.com/calcite-design-system/icons/) displayed in the header cell of the column. */
  icon?: Icon["icon"];
  /** The selection mode of the menu items. */
  selectionMode?: "none" | "single" | "multiple";
}

/** The configuration for the table's menu. */
export interface TableMenuConfig {
  /** Indicates whether the menu is disabled. Default value is `false`. */
  disabled?: boolean;
  /** The menu items within the table menu. */
  items: TableMenuItemConfig[];
  /** Indicates whether the menu is open. Default value is `false`. */
  open?: boolean;
}

/** The configuration for an individual menu item within the table menu. */
export interface TableMenuItemConfig {
  /** The function that executes when the menu item is clicked. */
  clickFunction: TableMenuItemConfigClickFunction;
  /** Indicates whether the menu item is disabled. Default value is `false`. */
  disabled?: boolean;
  /** A function that determines whether the menu item is hidden. Default value is `false`. */
  hidden?: TableMenuItemConfigHiddenFunction | boolean;
  /** The string value indicating the [Calcite icon](https://developers.arcgis.com/calcite-design-system/icons/) displayed for the menu item. */
  icon?: Icon["icon"];
  /**
   * This is the CSS class for the icon displayed for the menu item.
   *
   * @deprecated Since version 4.30. Use `icon` instead.
   */
  iconClass?: string;
  /** The text displayed for the menu item. */
  label: string;
  /** Indicates whether the menu item is selected. Default value is `false`. */
  selected?: boolean;
}

/**
 * The function that executes when the menu item is clicked.
 *
 * @param event - The event.
 */
export type TableMenuItemConfigClickFunction = (event: MouseEvent | KeyboardEvent) => void;

/**
 * A function that determines whether the menu item is hidden.
 *
 * @returns whether the menu item is hidden.
 */
export type TableMenuItemConfigHiddenFunction = () => boolean;