import type FieldFormat from "./FieldFormat.js";

export interface NumberFieldFormatProperties extends Partial<Pick<NumberFieldFormat, "maximumFractionDigits" | "minimumFractionDigits" | "useGrouping">> {}

export type Style = "decimal";

export type Grouping = "always" | "auto" | "never";

/**
 * The `NumberFieldFormat` class defines the formatting options for numeric field [types](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-Field.html#type). It is used in the [FieldConfiguration](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-FieldConfiguration.html) class to define the display format of fields in a [FeatureLayer](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html). It is also used in the [FieldInfo](https://developers.arcgis.com/javascript/latest/api-reference/esri-popup-FieldInfo.html) class to define the display format of fields content in a [PopupTemplate#content](https://developers.arcgis.com/javascript/latest/api-reference/esri-PopupTemplate.html#content).
 *
 * It applies to both the map's popup and any components/widgets that display the field.
 *
 * > [!WARNING]
 * >
 * > **Breaking change**
 * > Numeric fields with decimal values are now automatically formatted with a limit on decimal places. For example, a value such as `1.234566788` would display with all available decimal places in the FeatureTable. Now, if no field configurations are defined, components automatically limit the display to two decimal places (`1.23`). To customize this behavior, define field configurations on your layer.
 *
 * ### Numeric Format Mappings
 *
 * The following tables show equivalencies between the legacy [FieldInfoFormat#places](https://developers.arcgis.com/javascript/latest/api-reference/esri-popup-support-FieldInfoFormat.html#places) and [FieldInfoFormat#digitSeparator](https://developers.arcgis.com/javascript/latest/api-reference/esri-popup-support-FieldInfoFormat.html#digitSeparator)  values and `NumberFieldFormat` properties. The examples shown are for the `en-US` locale. Note that the actual display will vary based on the locale of the user.
 *
 * ---
 *
 * #### Integer Field Types
 *
 * | **Legacy** | **NumberFieldFormat equivalency** | **Example (en-US)** |
 * |---|---|---|
 * | `digitSeparator = true` | `useGrouping = "always"` | 1,234,567  |
 * | `digitSeparator = false` | `useGrouping = "never"` | 1234567 |
 *
 * ### Floating-point field types
 * | **Legacy** | **NumberFieldFormat equivalency** | **Example: (en-US) Input** | **`NumberFieldFormat` output** |
 * |---|---|---| --- |
 * | `digitSeparator = true`, `places = 4` | `useGrouping = "always"`, `minimumFractionDigits = 4`, `maximumFractionDigits = 4` | 1,234.5678 | 1,234.5678 |
 * | `digitSeparator = false`, `places = 4` | `useGrouping = "never"`, `minimumFractionDigits = 4`, `maximumFractionDigits = 4` | 1234.5678 | 1234.5678 |
 * | `digitSeparator = false`, `places = 3` | `useGrouping = "never"`, `minimumFractionDigits = 2`, `maximumFractionDigits = 3` | 1234.323443 | 1234.323 |
 * | `digitSeparator = true`, `places = 2` | `useGrouping = "auto"`, `minimumFractionDigits = 3`, `maximumFractionDigits = 3` | 1,234.323443 | 1,234.323 |
 *
 * ---
 *
 * @since 4.34
 * @see [FieldConfiguration](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-FieldConfiguration.html)
 * @see [MDN documentation - DateTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat)
 * @see [CLDR](https://cldr.unicode.org/)
 * @example
 * // Create a number field format
 * const numberFieldFormat = new NumberFieldFormat ({
 *   minimumFractionDigits: 1,
 *   maximumFractionDigits: 3,
 *   useGrouping: "never"
 * });
 *
 * // Create a field configuration object containing the number format
 * const numberFieldConfiguration = new FieldConfiguration ({
 *   name: "voterCount", // name of the field in the service
 *   fieldFormat: numberFieldFormat,
 *   alias: "Voter Count"
 * });
 *
 * // Create a feature layer and pass in the field configurations
 * const featureLayer = new FeatureLayer ({
 *   url: "url to feature layer",
 *   outFields: ["*"],
 *   fieldConfigurations: [numberFieldConfiguration] // add as many field configurations as needed
 * });
 */
export default class NumberFieldFormat extends FieldFormat {
  constructor(properties?: NumberFieldFormatProperties);
  /**
   * The maximum number of decimal places to display. If the number has more decimal places, it will be rounded to the nearest value with the specified number of decimal places. For example, if `maximumFractionDigits` is set to `2`, the number `3.456` will be displayed as `3.46`.
   *
   * @see [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat)
   */
  accessor maximumFractionDigits: number;
  /**
   * The minimum number of decimal places to display.
   * If the number has fewer decimal places, it will be padded with trailing zeros.
   * If the number has more decimal places, it will be rounded to the nearest value
   * with the specified number of decimal places.
   * For example, if `minimumFractionDigits` is set to `2`, the number `3.1` will be displayed as `3.10` and the number `3.456` will be displayed as `3.46`.
   *
   * @see [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat)
   */
  accessor minimumFractionDigits: number;
  /**
   * The formatting style to use. Support is currently limited to `decimal` style.
   *
   * @default decimal
   * @see [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat)
   */
  get style(): Style;
  /**
   * The type of field format.
   *
   * @default "number"
   */
  get type(): "number";
  /**
   * Indicates whether to use grouping separators, such as thousands separators. For example, if `useGrouping` is set to `always`, the number `1234567` will be displayed as `1,234,567`. If set to `never`, the number will be displayed as `1234567`. `auto` is the default value and uses grouping separators based on the locale and the number of digits.
   *
   * @default auto
   * @see [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat)
   */
  accessor useGrouping: Grouping;
}