/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import { defaultLocale, normalizeLocale, supportedLocales } from "@arcgis/toolkit/intl";
import { d as dateFromISO } from "./date.js";
import { g as getAssetPath } from "./runtime.js";
const translationCache = {};
const requestCache = {};
const extraNlsLocales = [
  "de-AT",
  "de-CH",
  "en-AU",
  "en-CA",
  "en-GB",
  "es-MX",
  "fr-CA",
  "fr-CH",
  "hi",
  "it-CH",
  "mk",
  "pt"
];
[...supportedLocales, ...extraNlsLocales];
function normalizeNlsLocale(locale) {
  if (!locale) {
    return defaultLocale;
  }
  const localeParts = locale.split("-");
  locale = `${localeParts[0].toLowerCase()}${localeParts.length >= 2 ? `-${localeParts[1].toUpperCase()}` : ""}`;
  if (extraNlsLocales.includes(locale)) {
    return locale;
  }
  return normalizeLocale(locale);
}
async function getLocaleData(locale) {
  locale = normalizeNlsLocale(locale);
  if (translationCache[locale]) {
    return translationCache[locale];
  }
  if (!requestCache[locale]) {
    requestCache[locale] = fetch(getAssetPath(`./assets/date-picker/nls/${locale}.json`)).then((resp) => resp.json()).catch(() => {
      console.error(`Native Language Support data for "${locale}" not found or invalid, falling back to english`);
      return getLocaleData(defaultLocale);
    });
  }
  return translationCache[locale] = await requestCache[locale];
}
function applyLocaleOverride(locale) {
  const localeOverrideMap = {
    "ar-SA": "ar"
    // see https://github.com/Esri/calcite-design-system/issues/11399
  };
  return localeOverrideMap[locale] || locale;
}
function getValueAsDateRange(value) {
  return value.map((v, index) => dateFromISO(v, index === 1));
}
function getSource(changes, stringProp, dateProp) {
  const stringPropChanged = changes.has(stringProp);
  const datePropChanged = changes.has(dateProp);
  if (stringPropChanged && !datePropChanged) {
    return stringProp;
  }
  if (datePropChanged && !stringPropChanged) {
    return dateProp;
  }
  return null;
}
function getMinMaxSource(changes, type) {
  return type === "min" ? getSource(changes, "min", "minAsDate") : getSource(changes, "max", "maxAsDate");
}
export {
  getValueAsDateRange as a,
  applyLocaleOverride as b,
  getLocaleData as c,
  getMinMaxSource as g
};
