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

/** @since 5.0 */
export type CellValue = null | undefined | string | number;

/** @since 5.0 */
export type TextAlign = "start" | "center" | "end";

/** @since 5.0 */
export type FeatureTableState = "disabled" | "loading" | "loaded" | "ready" | "error";

/** @since 5.0 */
export type GridSupportedColumns = Column;

/** @since 5.0 */
export type GridMultiSortPriority = "append" | "prepend";

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

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

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

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

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

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

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

/** @since 5.0 */
export type Direction = "asc" | "desc" | null | undefined;

/** @since 5.0 */
export interface ColumnTableMenuConfig extends TableMenuConfig {
  /**
   * The number of items to display in the column menu before displaying a scrollbar. The default is 4.
   *
   * @since 5.1
   */
  maxItems?: number;
  /**
   * The scale of the menu items in the menu. The default is "m".
   *
   * @since 5.1
   */
  scale?: "s" | "m" | "l";
  /**
   * The selection mode of the menu items.
   *
   * @since 5.0
   */
  selectionMode?: "none" | "single" | "multiple";
  /**
   * The string value indicating the [icon](https://developers.arcgis.com/calcite-design-system/icons/) displayed in the header cell of the column.
   *
   * @since 5.0
   */
  icon?: Icon["icon"];
}

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

/**
 * The configuration for the table's column visibility menu.
 *
 * @internal
 */
export interface TableColumnVisibilityMenuConfig {
  /**
   * Indicates frozen columns should be excluded from the menu's user interface and toggling actions.
   *
   * @internal
   */
  frozenColumnsExcluded?: boolean;
  /**
   * Determines where the menu's popover will be positioned relative to the menu's action.
   *
   * @internal
   */
  placement?: "auto" | "auto-start" | "auto-end" | "top" | "top-start" | "top-end" | "bottom" | "bottom-start" | "bottom-end" | "right" | "right-start" | "right-end" | "left" | "left-start" | "left-end" | "leading-start" | "leading" | "leading-end" | "trailing-end" | "trailing" | "trailing-start";
}

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

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

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

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

/** @since 5.0 */
export interface FeatureStoreEdits {}

/** @since 5.0 */
export interface DiscardPendingEditsParameters {}