
/**
 * The formatting options for date values.
 *
 * @see [SubstituteOptions](https://developers.arcgis.com/javascript/latest/api-reference/esri-intl-substitute.html#SubstituteOptions)
 * @example
 * const dateFormat = {
 *   type: "date",
 *   intlOptions: {
 *     year: "numeric",
 *     month: "numeric",
 *     day: "numeric",
 *     hour: "numeric",
 *     minute: "numeric"
 *   }
 * };
 *
 * let data = {
 *   time: Date.now()
 * };
 *
 * intl.substitute("Date: {time}", data, {
 *   format: {
 *     time: dateFormat
 *   }
 * });
 */
export interface DateTimeFormatOptions {
  /** The date format options for the [Intl.DateTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat) object. */
  intlOptions?: Intl.DateTimeFormatOptions;
  /** The type of this format. The value is always `"date"`. */
  type: "date";
}

/**
 * The formatting options for numeric values.
 *
 * @see [SubstituteOptions](https://developers.arcgis.com/javascript/latest/api-reference/esri-intl-substitute.html#SubstituteOptions)
 * @example
 * // Formats a number with a fixed number of fraction digits
 * const numberFormat = {
 *   type: "number",
 *   intlOptions: {
 *     style: "decimal",
 *     useGrouping: true,
 *     minimumFractionDigits: 2,
 *     maximumFractionDigits: 2
 *   }
 * });
 *
 * let data = {
 *   value: 10
 * };
 *
 * intl.substitute("A number: {value}", data, {
 *   value: numberFormat
 * });
 * @example
 * // Formats a number as currency, in Euros.
 * const currencyFormat = {
 *   type: "number",
 *   intlOptions: {
 *     style: "currency",
 *     currency: "EUR",
 *     currencyDisplay: "symbol"
 *   }
 * };
 *
 * let data = {
 *   amount: 14
 * };
 *
 * intl.substitute("Amount: {amount}", data, {
 *   amount: currencyFormat
 * });
 * @example
 * // Formats a number as a percentage.
 * const percentFormat = {
 *   type: "number",
 *   intlOptions: {
 *     style: "percent"
 *   }
 * };
 *
 * let data = {
 *   growth: 0.5
 * };
 *
 * intl.substitute("Growth: {growth}", data, {
 *   growth: percentFormat
 * });
 */
export interface NumberFormatOptions {
  /** The Intl number format options for the [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat) object. */
  intlOptions?: Intl.NumberFormatOptions;
  /** The type of this format. The value is always `"number"`. */
  type: "number";
}

/**
 * An object to specify substitution options.
 *
 * Use the [SubstituteOptions.format](https://developers.arcgis.com/javascript/latest/api-reference/esri-intl-substitute.html#SubstituteOptions) property to define the formatting for each value referenced in the string template.
 * `format` is a key-value pair object. Each key can either be:
 *   - a property of the `data` parameter or [substitute()](https://developers.arcgis.com/javascript/latest/api-reference/esri-intl.html#substitute)
 *   - a named formatter than can be referenced in the template string.
 *
 * In the following example, the `time` property from `data` will be formatted as a date with each component in numeric format.
 *
 * ```js
 * const data = {
 *   time: Date.now()
 * };
 *
 * intl.substitute("Date: {time}", data, {
 *   format: {
 *     time: {
 *       type: "date",
 *       intlOptions: {
 *         year: "numeric",
 *         month: "numeric",
 *         day: "numeric",
 *         hour: "numeric",
 *         minute: "numeric"
 *       }
 *     }
 *   }
 * });
 * ```
 *
 * The following example uses a named formatter to format the `time` property twice with different formatting options.
 *
 * ```js
 * const data = {
 *   time: Date.now()
 * };
 *
 * intl.substitute("In {time:monthFormat} of {time:yearFormat}", data, {
 *   format: {
 *     monthFormat: {
 *       type: "date",
 *       intlOptions: {
 *         month: "long"
 *       }
 *     },
 *     yearFormat: {
 *       type: "date",
 *       intlOptions: {
 *         year: "numeric"
 *       }
 *     }
 *   }
 * });
 * ```
 *
 * @see [substitute()](https://developers.arcgis.com/javascript/latest/api-reference/esri-intl.html#substitute)
 */
export interface SubstituteOptions {
  /** A hashmap of string keys to formatting options. */
  format?: Record<string, NumberFormatOptions | DateTimeFormatOptions | undefined>;
}