;
{
  try {
    let e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack;
    n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "960d28f2-95cd-44a4-a177-b07c181980e1", e._sentryDebugIdIdentifier = "sentry-dbid-960d28f2-95cd-44a4-a177-b07c181980e1");
  } catch (e) {
  }
}
;
import { useState, useEffect } from "preact/hooks";
import { a3 as createLogger, aa as useI18nContext } from "./StoreProvider-CqQrndhS.js";
import { a as datasetUtilities, d as datasetIdentifier } from "./datasetUtil-BHQp0-xL.js";
const logger$1 = createLogger();
const countriesImports = /* @__PURE__ */ Object.assign({ "../countries/de-DE.json": () => import("./de-DE-B3nctkG8.js"), "../countries/el-GR.json": () => import("./el-GR-CdgLZhuO.js"), "../countries/en-US.json": () => import("./en-US-DSoLr6rp.js"), "../countries/es-ES.json": () => import("./es-ES-BRfK6tX7.js"), "../countries/fr-FR.json": () => import("./fr-FR-Dk6Lw2On.js"), "../countries/it-IT.json": () => import("./it-IT-D7G4BaP7.js"), "../countries/ja-JP.json": () => import("./ja-JP-DTW_hY1L.js"), "../countries/nl-NL.json": () => import("./nl-NL-CFzm75Jw.js"), "../countries/pt-PT.json": () => import("./pt-PT-DpDxAynk.js"), "../countries/sv-SE.json": () => import("./sv-SE-rckxD-43.js") });
const loadCountriesDataset = async (locale) => {
  const importForLocale = countriesImports[`../countries/${locale}.json`];
  if (!importForLocale) {
    logger$1.warn(`No countries dataset for ${locale}, falling back to en-US`);
    return (await import("./en-US-DSoLr6rp.js")).default;
  }
  return (await importForLocale()).default;
};
const logger = createLogger();
const statesImports = /* @__PURE__ */ Object.assign({ "../states/AU/en-US.json": () => import("./en-US-Do3mE4BR.js"), "../states/BR/en-US.json": () => import("./en-US-DWT3bRZC.js"), "../states/BR/pt-BR.json": () => import("./pt-BR-CTXtdAVc.js"), "../states/CA/en-US.json": () => import("./en-US-PLYPmyFJ.js"), "../states/JP/en-US.json": () => import("./en-US-QbdqemZi.js"), "../states/JP/ja-JP.json": () => import("./ja-JP-DU7yCJYq.js"), "../states/NZ/en-US.json": () => import("./en-US-C_9Fc9mP.js"), "../states/US/en-US.json": () => import("./en-US-9KQC6F8-.js") });
const loadStatesDataset = async (country, locale) => {
  const importForLocale = statesImports[`../states/${country}/${locale}.json`];
  if (!importForLocale) {
    logger.warn(`No ${country} states dataset for ${locale}, falling back to en-US`);
    const fallbackImport = statesImports[`../states/${country}/en-US.json`];
    return (await fallbackImport()).default;
  }
  return (await importForLocale()).default;
};
const loadDataset = async (identifier, locale) => {
  if (identifier === datasetIdentifier.country) {
    return loadCountriesDataset(locale);
  }
  if (identifier.startsWith("states")) {
    const country = identifier.slice(identifier.indexOf("/") + 1);
    return loadStatesDataset(country, locale);
  }
  throw new Error(`Unknown dataset: ${identifier}`);
};
const getDataset = async (identifier, locale) => {
  const datasetUtils = datasetUtilities(locale);
  const dataset = datasetUtils.getDataset(identifier);
  if (dataset) {
    return new Promise((resolve) => {
      resolve(dataset);
    });
  }
  return loadDataset(identifier, locale).then((datasetResponse) => {
    datasetUtils.setDataset(identifier, datasetResponse);
    return datasetResponse;
  });
};
function useDataset(datasetIdentifier2, skip) {
  const { i18n } = useI18nContext();
  const [dataset, setDataset] = useState([]);
  const [loaded, setLoaded] = useState(false);
  useEffect(() => {
    if (skip) return;
    getDataset(datasetIdentifier2, i18n.locale).then((response) => {
      const result = response && response.length ? response : [];
      setDataset(result);
    }).catch(() => {
      setDataset([]);
    }).finally(() => {
      setLoaded(true);
    });
  }, [datasetIdentifier2, i18n.locale, skip]);
  return { dataset, loaded };
}
export {
  useDataset as u
};
