import type SelectionManager from "../../../views/SelectionManager.js";
import type SelectionOperation from "../../../views/selection/SelectionOperation.js";
import type { EventedAccessor } from "../../../core/Evented.js";
import type { SelectableViewUnion, SelectionOperationEvents, SelectionOperationType, SelectionSource, SelectionToolName } from "../../../views/selection/types.js";
import type { SelectionToolConfig, SelectionToolOptions, SelectionToolbarState } from "./types.js";

/** @internal */
export interface SelectionToolbarViewModelProperties extends Partial<Pick<SelectionToolbarViewModel, "continuousSelectionEnabled" | "defaultLassoToolOptions" | "defaultOperationType" | "defaultPointToolOptions" | "defaultRectangleToolOptions" | "layerViewPreferenceEnabled" | "persistSelection" | "returnFeatureTitleFields" | "returnGeometry" | "selectionManager" | "selectOnComplete" | "sources" | "toolConfigs" | "view">> {}

/**
 * Events emitted by SelectionToolbarViewModel.
 *
 * @internal
 */
export interface SelectionToolbarViewModelEvents {
  /** @internal */
  "before-activate": CustomEvent<{ toolName: SelectionToolName | null; }>;
  /** @internal */
  complete: SelectionOperationEvents["complete"];
  /** @internal */
  "selection-change": SelectionOperationEvents["selection-change"];
}

/**
 * Manages interactive selection operations for rectangle, lasso, and custom selection tools.
 *
 * @internal
 */
export default class SelectionToolbarViewModel extends EventedAccessor {
  /** @internal */
  "@eventTypes": SelectionToolbarViewModelEvents;
  /** @internal */
  constructor(properties?: SelectionToolbarViewModelProperties);
  /** @internal */
  get activeOperation(): SelectionOperation | null | undefined;
  /**
   * @default false
   * @internal
   */
  accessor continuousSelectionEnabled: boolean;
  /**
   * Default configuration for the lasso tool.
   *
   * @internal
   */
  accessor defaultLassoToolOptions: SelectionToolOptions;
  /**
   * @default "add"
   * @internal
   */
  accessor defaultOperationType: SelectionOperationType;
  /**
   * Default configuration for the point tool.
   *
   * @internal
   */
  accessor defaultPointToolOptions: SelectionToolOptions;
  /**
   * Default configuration for the rectangle tool.
   *
   * @internal
   */
  accessor defaultRectangleToolOptions: SelectionToolOptions;
  /**
   * Reference to the selection manager in use by the toolbar.
   *
   * @internal
   */
  get effectiveSelectionManager(): SelectionManager | null | undefined;
  /** @internal */
  get effectiveSources(): SelectionSource[];
  /**
   * @default true
   * @internal
   */
  accessor layerViewPreferenceEnabled: boolean;
  /**
   * @default true
   * @internal
   */
  accessor persistSelection: boolean;
  /**
   * @default false
   * @internal
   */
  accessor returnFeatureTitleFields: boolean;
  /**
   * @default true
   * @internal
   */
  accessor returnGeometry: boolean;
  /** @internal */
  accessor selectionManager: SelectionManager | null | undefined;
  /**
   * @default true
   * @internal
   */
  accessor selectOnComplete: boolean;
  /** @internal */
  accessor sources: SelectionSource[] | null | undefined;
  /** @internal */
  get state(): SelectionToolbarState;
  /** @internal */
  accessor toolConfigs: SelectionToolConfig[];
  /**
   * The view from which the widget will operate.
   *
   * @internal
   */
  accessor view: SelectableViewUnion | null | undefined;
  /**
   * Activates a selection operation.
   *
   * @param options - Optional tool and operation configuration.
   * @returns The active operation, or `undefined` when activation is blocked.
   * @internal
   */
  activate(options?: SelectionToolOptions): SelectionOperation | undefined;
  /**
   * Activates a configured tool by name.
   *
   * @param toolName - The tool identifier to activate.
   * @returns The active operation, or `undefined` when no matching tool configuration is available.
   * @internal
   */
  activateTool(toolName: SelectionToolName): SelectionOperation | undefined;
  /**
   * Cancels the active selection operation, if present.
   *
   * @internal
   */
  cancel(): void;
  /**
   * Toggles a tool by name.
   *
   * @param toolName - The tool identifier to toggle.
   * @returns The active operation when toggled on, or `undefined` when toggled off.
   * @internal
   */
  toggleTool(toolName: SelectionToolName): SelectionOperation | undefined;
}