import type Color from "../Color.js";
import type Point from "../geometry/Point.js";
import type Polygon from "../geometry/Polygon.js";
import type Polyline from "../geometry/Polyline.js";
import type Layer from "../layers/Layer.js";
import type Sublayer from "../layers/support/Sublayer.js";
import type LayerView from "../views/layers/LayerView.js";
import type { RelationshipFocus } from "../renderers/support/types.js";
import type { SymbolUnion } from "../symbols/types.js";

/**
 * The z axis orientation.
 *
 * @since 5.0
 */
export interface Axes {
  /**
   * z axis orientation.
   *
   * @since 5.0
   */
  z?: number;
}

/**
 * Describes a point in terms of a location, a [Point](https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Point.html), and a coordinate, a string.
 *
 * @since 5.0
 */
export interface Position {
  /**
   * A point geometry representing the location described by the conversion.
   *
   * @since 5.0
   */
  location?: Point | null;
  /**
   * A string representing the location.
   *
   * @since 5.0
   */
  coordinate?: string | null;
}

/** @since 5.0 */
export type Mode = "live" | "capture";

/**
 * This object describes how a Format should be projected and formatted for display.  Used to define
 * custom Formats that require custom conversion and/or projection logic.
 *
 * @since 5.0
 */
export interface ConversionInfo {
  /**
   * A function that takes a point and returns a [Position](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-types.html#Position).
   *
   * @since 5.0
   */
  convert?: ConvertFunction;
  /**
   * A function that takes a string and returns a Point.
   *
   * @since 5.0
   */
  reverseConvert?: ReverseConvertFunction;
}

/**
 * A user-provided function that converts a [Point](https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Point.html) into a
 * [Position](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-types.html#Position). This function may
 * be necessary to provide as part of [ConversionInfo](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-types.html#ConversionInfo)
 * when creating a custom [Format](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-CoordinateConversion-support-Format.html).
 *
 * @param point - A point to be converted.
 * @returns The returned position.
 * @since 5.0
 */
export type ConvertFunction = (point: Point) => Position;

/**
 * A user-provided function that converts a coordinate string into a [Point](https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Point.html).
 * This function may be necessary to provide as part of [ConversionInfo](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-types.html#ConversionInfo)
 * when creating a custom [Format](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-CoordinateConversion-support-Format.html).
 *
 * @param coordinate - The string to be reversed.
 * @returns The returned point
 * @since 5.0
 */
export type ReverseConvertFunction = (coordinate: string) => Point;

/**
 * A coordinate segment represents one piece of a coordinate string.
 *
 * > [!WARNING]
 * >
 * > A MGRS coordinate, for example `30UVG898998`, is described by four segments:
 * > 1. Alias `Z`, the gridzone: `30U`
 * > 2. Alias `S`, the 100,000 meter square designator: `VG`
 * > 3. Alias `X`, the easting (x coordinate with respect to the 10,000 meter square): `898`
 * > 4. Alias `Y`, the northing (y coordinate with respect to the 10,000 meter square): `998`
 *
 * @since 5.0
 */
export interface CoordinateSegment {
  /**
   * A string that provides the name for this segment of a coordinate string.
   *
   * @since 5.0
   */
  alias: string;
  /**
   * A string that describes the role of this segment.
   *
   * @since 5.0
   */
  description: string;
  /**
   * A regular expression that should extract this segment from the complete coordinate.
   *
   * @since 5.0
   */
  searchPattern: RegExp;
}

/**
 * An object that defines a layer, optional sublayer IDs, and a custom title for legend display.
 * Use this to specify which layers and sublayers appear in the legend and how they are labeled with
 * [layerInfos](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Legend-LegendViewModel.html).
 *
 * @since 5.0
 */
export interface LayerInfo {
  /**
   * A layer to display in the legend.
   *
   * @since 5.0
   */
  layer: Layer | Sublayer;
  /**
   * Specifies a title for the layer to display above its symbols and descriptions.
   * If no title is specified the service name is used.
   *
   * @since 5.0
   */
  title: string;
  /**
   * The IDs of the sublayers for which to display legend information.
   * Only applicable if the `layer` is a [MapImageLayer](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-MapImageLayer.html), [SubtypeGroupLayer](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-SubtypeGroupLayer.html)
   * or [WMSLayer](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-WMSLayer.html).
   *
   * @since 5.0
   */
  sublayerIds?: number[];
}

/**
 * Properties defining the scheme of each of the supported [legendElement](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Legend-support-ActiveLayerInfo.html#legendElements).
 *
 * @since 5.0
 */
export type LegendElement = SymbolTableElement | ColorRampElement | StretchRampElement | OpacityRampElement | SizeRampElement | HeatmapRampElement | RelationshipRampElement | UnivariateColorSizeRampElement | PieChartRampElement;

/**
 * Properties defining the scheme of each SymbolTableElementType.
 *
 * @since 5.0
 */
export type SymbolTableElementType = ImageSymbolTableElementInfo | SymbolTableElementInfo | LegendElement;

/**
 * Describes the schema of the SymbolTableElement used as a [legendElement](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Legend-support-ActiveLayerInfo.html#legendElements). This
 * legend element is used for [UniqueValueRenderer](https://developers.arcgis.com/javascript/latest/api-reference/esri-renderers-UniqueValueRenderer.html) and
 * [ClassBreaksRenderer](https://developers.arcgis.com/javascript/latest/api-reference/esri-renderers-ClassBreaksRenderer.html).
 *
 * @since 5.0
 */
export interface SymbolTableElement {
  /**
   * The type of this element is always `symbol-table`.
   *
   * @since 5.0
   */
  type: "symbol-table";
  /**
   * The title of the renderer as displayed in the legend.
   *
   * @since 5.0
   */
  title?: RendererTitle | DotDensityTitle | string | null;
  /**
   * An
   *   array of each symbol/category/break rendered for the symbol table. For example, this may be individual
   *   breaks for a ClassBreaksRenderer, or unique values for a UniqueValueRenderer.
   *
   * @since 5.0
   */
  infos: SymbolTableElementType[];
  /**
   * Only used for renderers set to ImageryLayers. Indicates the type of
   *   renderer set on the layer (e.g. `stretched` or `Unique Values`).
   *
   * @since 5.0
   */
  legendType?: string | null;
}

/**
 * Properties defining the scheme of the SymbolTableElementInfo.
 *
 * @since 5.0
 */
export interface SymbolTableElementInfo {
  /**
   * The symbol for the corresponding `value` in the legend.
   *
   * @since 5.0
   */
  symbol: SymbolUnion;
  /**
   * The
   *   title of the renderer as displayed in the Legend.
   *
   * @since 5.0
   */
  label?: RampTitle | string | null;
  /**
   * The value corresponding with the given `symbol` in the legend.
   *
   * @since 5.0
   */
  value?: any;
  /**
   * The size of the symbol in points.
   *
   * @since 5.0
   */
  size?: number | null;
  /**
   * A preview of the symbol element as displayed in the legend.
   *
   * @since 5.0
   */
  preview?: HTMLElement | null;
  /**
   * The aria-label for the preview element.
   *
   * @since 5.0
   */
  previewAriaLabel?: RendererTitle | DotDensityTitle | string | null;
}

/**
 * Properties defining the scheme of each of the ImageSymbolTableElementInfo. This applies only to
 * ImageryLayer renderers.
 *
 * @since 5.0
 */
export interface ImageSymbolTableElementInfo {
  /**
   * The label of the category corresponding to the given image.
   *
   * @since 5.0
   */
  label?: StretchMultibandTitle | string | null;
  /**
   * The data URI of the image representing a colored pixel in the renderer.
   *
   * @since 5.0
   */
  src: string;
  /**
   * The aria-label for the preview element.
   *
   * @since 5.0
   */
  previewAriaLabel?: RendererTitle | DotDensityTitle | string | null;
  /**
   * The opacity of the image (`0` to `1`).
   *
   * @since 5.0
   */
  opacity?: number | null;
  /**
   * The width of the image in pixels.
   *
   * @since 5.0
   */
  width?: number | null;
  /**
   * The height of the image in pixels.
   *
   * @since 5.0
   */
  height?: number | null;
}

/**
 * Describes the schema of the ColorRampElement used as a [legendElement](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Legend-support-ActiveLayerInfo.html#legendElements).
 *
 * @since 5.0
 */
export interface ColorRampElement {
  /**
   * The type of this element is always `color-ramp`.
   *
   * @since 5.0
   */
  type: "color-ramp";
  /**
   * The title of the color ramp as displayed in the legend.
   *
   * @since 5.0
   */
  title?: RampTitle | string | null;
  /**
   * The
   *   individual color stops rendered in the legend that correspond to the color visual variable in the renderer.
   *
   * @since 5.0
   */
  infos: ColorRampStop[];
  /**
   * A preview of the element as displayed in the legend.
   *
   * @since 5.0
   */
  preview?: HTMLElement | null;
}

/**
 * Describes the schema of the StretchRampElement used as a [legendElement](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Legend-support-ActiveLayerInfo.html#legendElements).
 *
 * @since 5.0
 */
export interface StretchRampElement {
  /**
   * The type of this element is always `stretch-ramp`.
   *
   * @since 5.0
   */
  type: "stretch-ramp";
  /**
   * The title of the color ramp as displayed in the legend.
   *
   * @since 5.0
   */
  title?: RampTitle | string | null;
  /**
   * The
   *   individual color stops rendered in the legend that correspond to the color visual variable in the renderer.
   *
   * @since 5.0
   */
  infos: ColorRampStop[];
  /**
   * A preview of the element as displayed in the legend.
   *
   * @since 5.0
   */
  preview?: HTMLElement | null;
}

/**
 * Describes the schema of the OpacityRampElement used as a [legendElement](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Legend-support-ActiveLayerInfo.html#legendElements).
 *
 * @since 5.0
 */
export interface OpacityRampElement {
  /**
   * The type of this element is always `opacity-ramp`.
   *
   * @since 5.0
   */
  type: "opacity-ramp";
  /**
   * The title of the opacity ramp as displayed in the legend.
   *
   * @since 5.0
   */
  title?: RampTitle | string | null;
  /**
   * The
   *   individual opacity stops rendered in the legend that correspond to the opacity visual variable in the renderer.
   *
   * @since 5.0
   */
  infos: OpacityRampStop[];
  /**
   * A preview of the element as displayed in the legend.
   *
   * @since 5.0
   */
  preview?: HTMLElement | null;
}

/**
 * Describes the schema of the SizeRampElement used as a [legendElement](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Legend-support-ActiveLayerInfo.html#legendElements).
 *
 * @since 5.0
 */
export interface SizeRampElement {
  /**
   * The type of this element is always `size-ramp`.
   *
   * @since 5.0
   */
  type: "size-ramp";
  /**
   * The title of the size ramp as displayed in the legend.
   *
   * @since 5.0
   */
  title?: ClusterTitle | RampTitle | string | null;
  /**
   * The
   *   individual size stops rendered in the legend that correspond to the size visual variable in the renderer.
   *
   * @since 5.0
   */
  infos: SizeRampStop[];
  /**
   * The theme of this element.
   *
   * @since 5.0
   */
  theme?: "spike" | null;
}

/**
 * Describes the schema of the HeatmapRampElement used as a [legendElement](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Legend-support-ActiveLayerInfo.html#legendElements).
 *
 * @since 5.0
 */
export interface HeatmapRampElement {
  /**
   * The type of this element is always `heatmap-ramp`.
   *
   * @since 5.0
   */
  type: "heatmap-ramp";
  /**
   * The title of the heatmap ramp as displayed in the legend.
   *
   * @since 5.0
   */
  title?: RendererTitle | string | null;
  /**
   * The
   *   individual color stops rendered in the legend that correspond to the heatmap colorStops in the renderer.
   *
   * @since 5.0
   */
  infos: HeatmapRampStop[];
  /**
   * A preview of the element as displayed in the legend.
   *
   * @since 5.0
   */
  preview?: HTMLElement | null;
}

/**
 * Describes the schema of the RelationshipRampElement used as a [legendElement](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Legend-support-ActiveLayerInfo.html#legendElements).
 *
 * @since 5.0
 */
export interface RelationshipRampElement {
  /**
   * The type of this element is always `relationship-ramp`.
   *
   * @since 5.0
   */
  type: "relationship-ramp";
  /**
   * The number of classes for each field comprising the renderer. Can either
   *   be 2, 3, or 4.
   *
   * @since 5.0
   */
  numClasses: number;
  /**
   * Determines the orientation of the Legend. Values can be `HH`, `HL`, `LH`, `LL`.
   *
   * @since 5.0
   */
  focus: RelationshipFocus;
  /**
   * A 2-dimensional array of colors as displayed in the legend grid.
   *
   * @since 5.0
   */
  colors: Color[][];
  /**
   * The labels for
   *   each corner of the legend.
   *
   * @since 5.0
   */
  labels: RelationshipLabels;
  /**
   * The rotation of the legend in degrees (0-360). `0` degrees displays the legend
   *   as a square with the `LL` cell in the bottom left corner of the legend and the `HH` cell in the top right corner.
   *
   * @since 5.0
   */
  rotation: number;
  /**
   * The title of the renderer as displayed in the legend.
   *
   * @since 5.0
   */
  title?: string | null;
  /**
   * Info objects associated with the relationship renderer.
   *
   * @since 5.0
   */
  infos?: any[] | null;
}

/**
 * Describes the schema of the UnivariateColorSizeRampElement used as a [legendElement](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Legend-support-ActiveLayerInfo.html#legendElements).
 *
 * @since 5.0
 */
export interface UnivariateColorSizeRampElement {
  /**
   * The type of this element is `univariate-above-and-below-ramp` or `univariate-color-size-ramp`.
   *
   * @since 5.0
   */
  type: "univariate-above-and-below-ramp" | "univariate-color-size-ramp";
  /**
   * The title of the color ramp as displayed in the legend.
   *
   * @since 5.0
   */
  title?: ClusterTitle | RampTitle | string | null;
  /**
   * The
   *   individual color stops rendered in the legend that correspond to the color visual variable in the renderer.
   *
   * @since 5.0
   */
  infos: (SizeRampElement | ColorRampElement)[];
}

/**
 * Describes the schema of the UnivariateColorSizeRampElement used as a [legendElement](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Legend-support-ActiveLayerInfo.html#legendElements).
 *
 * @since 5.0
 */
export interface PieChartRampElement {
  /**
   * The type of this element is always `pie-chart-ramp`.
   *
   * @since 5.0
   */
  type: "pie-chart-ramp";
  /**
   * The title of the color ramp as displayed in the legend.
   *
   * @since 5.0
   */
  title?: RendererTitle | string | null;
  /**
   * The
   *   individual color stops rendered in the legend that correspond to the color visual variable in the renderer.
   *
   * @since 5.0
   */
  infos: SymbolTableElementInfo[];
  /**
   * A preview of the element as displayed in the legend.
   *
   * @since 5.0
   */
  preview?: HTMLElement | null;
}

/**
 * Describes the schema of the RendererTitle element.
 *
 * @since 5.0
 */
export interface RendererTitle {
  /**
   * The title of the renderer as displayed in the legend.
   *
   * @since 5.0
   */
  title?: string | null;
  /**
   * The field name used in the renderer. This is used in the
   *   generated title of the renderer in the legend.
   *
   * @since 5.0
   */
  field?: string | null;
  /**
   * If a normalization field is provided to the renderer, this field
   *   is also used in the generated title for the renderer in the legend.
   *
   * @since 5.0
   */
  normField?: string | null;
  /**
   * Indicates if a percentage is used in the normalization of the
   *   renderer. This is used to create a more readable legend for that scenario.
   *
   * @since 5.0
   */
  normByPct?: boolean | null;
}

/**
 * Describes the schema of the DotDensityTitle element.
 *
 * @since 5.0
 */
export interface DotDensityTitle {
  /**
   * The value.
   *
   * @since 5.0
   */
  value: number;
  /**
   * The unit.
   *
   * @since 5.0
   */
  unit?: string | null;
}

/**
 * Describes the schema of the ClusterTitle element.
 *
 * @since 5.0
 */
export interface ClusterTitle {
  /**
   * Whether to show the count.
   *
   * @since 5.0
   */
  showCount: boolean;
}

/**
 * Describes the schema of the RampTitle element.
 *
 * @since 5.0
 */
export interface RampTitle {
  /**
   * The field name used in a visual variable of a renderer. This is used in the
   *   generated title of the corresponding ramp in the legend.
   *
   * @since 5.0
   */
  field?: string | null;
  /**
   * If provided, the normalization field name used in a visual variable of a renderer.
   *   This is used in the generated title of the corresponding ramp in the legend.
   *
   * @since 5.0
   */
  normField?: string | null;
  /**
   * If `true`, the legend formats to display the field and normalization field as a ratio.
   *
   * @since 5.0
   */
  ratio: boolean;
  /**
   * If `true`, the legend formats to display the field and normalization field as a percentage.
   *
   * @since 5.0
   */
  ratioPercent: boolean;
  /**
   * If `true`, the legend formats to display the field and normalization field as a percentage of total.
   *
   * @since 5.0
   */
  ratioPercentTotal: boolean;
}

/**
 * Describes the schema of the StretchMultibandTitle element.
 *
 * @since 5.0
 */
export interface StretchMultibandTitle {
  /**
   * The color name.
   *
   * @since 5.0
   */
  colorName: string;
  /**
   * The band name.
   *
   * @since 5.0
   */
  bandName: string;
}

/**
 * Describes the schema of the SizeRampStop element. Each SizeRampStop represents a single stop of the
 * [SizeVariable](https://developers.arcgis.com/javascript/latest/api-reference/esri-renderers-visualVariables-SizeVariable.html) referenced in the renderer.
 *
 * @since 5.0
 */
export interface SizeRampStop {
  /**
   * The label in the legend describing features with the given `symbol` and `value`.
   *
   * @since 5.0
   */
  label: string;
  /**
   * The value of the size visual variable [stop](https://developers.arcgis.com/javascript/latest/api-reference/esri-renderers-visualVariables-SizeVariable.html#stops).
   *
   * @since 5.0
   */
  value?: any | null;
  /**
   * The symbol corresponding to the value of the stop in the renderer.
   *
   * @since 5.0
   */
  symbol: SymbolUnion;
  /**
   * The size of the visual variable [stop](https://developers.arcgis.com/javascript/latest/api-reference/esri-renderers-visualVariables-ColorVariable.html#stops) in points.
   *
   * @since 5.0
   */
  size?: number | {
      width: number;
      height: number;
  } | null;
  /**
   * The width of the outline in points.
   *
   * @since 5.0
   */
  outlineSize?: number | null;
  /**
   * The HTML element rendered in the legend representing features with the given value.
   *
   * @since 5.0
   */
  preview?: HTMLElement | null;
}

/**
 * Describes the schema of the ColorRampStop element. Each ColorRampStop represents a single stop of the
 * [ColorVariable](https://developers.arcgis.com/javascript/latest/api-reference/esri-renderers-visualVariables-ColorVariable.html) referenced in the renderer.
 *
 * @since 5.0
 */
export interface ColorRampStop {
  /**
   * The value of the color visual variable [stop](https://developers.arcgis.com/javascript/latest/api-reference/esri-renderers-visualVariables-ColorVariable.html#stops).
   *
   * @since 5.0
   */
  value: number | string | null;
  /**
   * The color of the visual variable [stop](https://developers.arcgis.com/javascript/latest/api-reference/esri-renderers-visualVariables-ColorVariable.html#stops).
   *
   * @since 5.0
   */
  color: Color;
  /**
   * The label in the legend describing features with the given `color` and `value`.
   *
   * @since 5.0
   */
  label: string | null;
}

/**
 * Describes the schema of the OpacityRampStop element. Each OpacityRampStop represents a single stop of the
 * [OpacityVariable](https://developers.arcgis.com/javascript/latest/api-reference/esri-renderers-visualVariables-OpacityVariable.html) referenced in the renderer. The opacity value of
 * each stop is indicated in the [alpha](https://developers.arcgis.com/javascript/latest/api-reference/esri-Color.html#a) property of the `color` object.
 *
 * @since 5.0
 */
export interface OpacityRampStop {
  /**
   * The value of the opacity visual variable [stop](https://developers.arcgis.com/javascript/latest/api-reference/esri-renderers-visualVariables-OpacityVariable.html#stops).
   *
   * @since 5.0
   */
  value: number;
  /**
   * The color of the visual variable [stop](https://developers.arcgis.com/javascript/latest/api-reference/esri-renderers-visualVariables-OpacityVariable.html#stops).
   *   The opacity corresponding to the given `value` is indicated in the [alpha](https://developers.arcgis.com/javascript/latest/api-reference/esri-Color.html#a) property of the color object.
   *
   * @since 5.0
   */
  color: Color;
  /**
   * The label in the legend describing features with the given `color` and `value`.
   *
   * @since 5.0
   */
  label: string;
}

/**
 * Describes the schema of the HeatmapRampStop element. Each HeatmapRampStop represents a single `colorStop` of the
 * [Heatmap color stops](https://developers.arcgis.com/javascript/latest/api-reference/esri-renderers-HeatmapRenderer.html#colorStops) referenced in the renderer.
 *
 * @since 5.0
 */
export interface HeatmapRampStop {
  /**
   * The color of the pixel corresponding to the appropriate pixel `ratio`. This value is typically
   *   between `0` and `1`.
   *
   * @since 5.0
   */
  color: Color;
  /**
   * The ratio of a pixel's intensity value to the minPixelIntensity of the renderer.
   *   The ratio of each pixel is matched to the corresponding color.
   *
   * @since 5.0
   */
  ratio: number;
  /**
   * The label of the color stop displayed in the legend. Typically only the first and last
   *   stops have labels.
   *
   * @since 5.0
   */
  label: string;
}

/**
 * Describes the schema of the RelationshipLabels element. These labels are rendered in the corners of the square
 * that represent the relationship renderer in the legend.
 *
 * @since 5.0
 */
export interface RelationshipLabels {
  /**
   * The label corresponding with the top corner of the legend if the focus
   *   is set to `HH`. This
   *   describes values that are considered high in both field 1 and field 2 (HH).
   *
   * @since 5.0
   */
  top: string;
  /**
   * The label corresponding with the bottom corner of the legend if the focus is
   *   set to `HH`. This
   *   describes values that are considered low in both field 1 and field 2 (LL).
   *
   * @since 5.0
   */
  bottom: string;
  /**
   * The label corresponding with the left corner of the legend (if the focus
   *   is set to `HH`). This describes features where the value of field 1 is high and the value of field 2 is low (HL).
   *
   * @since 5.0
   */
  left: string;
  /**
   * The label corresponding with the right corner of the legend (if the focus
   *   is set to `HH`). This describes features where the value of field 2 is high and the value of field 1 is low (LH).
   *
   * @since 5.0
   */
  right: string;
}

/**
 * The following properties define an attribution item that contains the attribution text for a layer.
 *
 * @since 5.0
 */
export interface AttributionItem {
  /**
   * The attribution text.
   *
   * @since 5.0
   */
  readonly text: string;
  /**
   * The layer view that has the attribution text.
   *
   * @since 5.0
   */
  readonly layerView: LayerView;
}

/** @since 5.0 */
export type MeasurementState = "disabled" | "ready" | "measuring" | "measured";

/** @since 5.0 */
export interface AreaMeasurement {
  /**
   * Measurement area.
   *
   * @since 5.0
   */
  geometry: Polygon;
  /**
   * The area (m²).
   *
   * @since 5.0
   */
  area: number;
  /**
   * The perimeter (m).
   *
   * @since 5.0
   */
  perimeter: number;
}

/** @since 5.0 */
export interface AreaMeasurementLabel {
  /**
   * The area (m²).
   *
   * @since 5.0
   */
  area: string;
  /**
   * The perimeter (m).
   *
   * @since 5.0
   */
  perimeter: string;
}

/** @since 5.0 */
export interface LinearMeasurement {
  /**
   * Measurement line.
   *
   * @since 5.0
   */
  geometry: Polyline;
  /**
   * Line length (m).
   *
   * @since 5.0
   */
  length: number;
}

/**
 * A dom node owner.
 *
 * @since 5.0
 */
export interface DomNodeOwner {
  /**
   * The dom node.
   *
   * @since 5.0
   */
  domNode: HTMLElement;
}

/** @since 5.0 */
export type SliderFormatType = "average" | "min" | "max" | "tick" | "value";

/**
 * Function used to format labels. This function should be set to the
 * [Histogram.labelFormatFunction](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Histogram.html#labelFormatFunction) property. This function fires
 * every time a label is created or updated on the histogram.
 *
 * @param value - The value for the line on the data axis.
 * @param type - The label type. Currently, the only supported type is `average`.
 * @param index - The index of the data line.
 * @returns The formatted value of the label.
 * @since 5.0
 */
export type HistogramLabelFormatFunction = (value: number, type?: "average", index?: number) => string;

/**
 * Function used to format labels. This function should be set to the
 * [Slider.labelFormatFunction](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Slider.html#labelFormatFunction) property. It fires
 * each time a label is created or updated on the slider.
 *
 * @param value - The value of the thumb to be labeled.
 * @param type - The label type. Valid types include `average`, `min`, `max`, `tick`, and `value`.
 * @param index - The index of the thumb (or [value](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Slider.html#values)).
 * @returns The formatted value of the label.
 * @since 5.0
 */
export type LabelFormatFunction = (value: number, type?: SliderFormatType, index?: number) => string;

/**
 * Function used to format thumb labels. This function should be set to the
 * [SmartMappingSliderBase.labelFormatFunction](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-smartMapping-SmartMappingSliderBase.html#labelFormatFunction) property. This function fires
 * every time a label is created or updated on the slider.
 *
 * @since 5.0
 * @param value - The value of the thumb.
 * @param type - The label type. Valid types include `average`, `min`, `max`, and `value`.
 * @param index - The index of the thumb (or [value](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-smartMapping-SmartMappingSliderViewModel.html#values)).
 * @returns The formatted value for the label.
 */
export type InputFormatFunction = LabelFormatFunction;

/**
 * Function definition for the
 * [Slider.inputParseFunction](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Slider.html#inputParseFunction) property. It fires
 * each time the user modifies slider input by key entry.
 *
 * @param value - The formatted input value of the thumb to be parsed.
 * @param type - The label type. Valid types include `average`, `min`, `max`, `tick`, and `value`.
 * @param index - The index of the thumb (or [value](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Slider.html#values)).
 * @returns The parsed number value of the thumb.
 * @since 5.0
 */
export type InputParseFunction = (value: string, type?: "average" | "min" | "max" | "tick" | "value", index?: number) => number;