'use client';
import {
  en_default
} from "./chunk-HVMAGUFA.mjs";
import {
  __glob
} from "./chunk-D4GAAQMM.mjs";

// src/contexts/SessionContext.tsx
import { createContext, useContext } from "react";
import { jsx } from "react/jsx-runtime";
var SessionContext = createContext(null);
function SessionProvider({
  sessionManager,
  children
}) {
  return /* @__PURE__ */ jsx(SessionContext.Provider, { value: sessionManager, children });
}
function useSessionContext() {
  const context = useContext(SessionContext);
  if (!context) {
    throw new Error("useSessionContext must be used within SessionProvider");
  }
  return context;
}

// src/components/Toast.tsx
import React, { useEffect, useState } from "react";
import { createPortal } from "react-dom";
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
var icons = {
  success: /* @__PURE__ */ jsx2("svg", { className: "semiont-toast-icon", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx2("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M5 13l4 4L19 7" }) }),
  error: /* @__PURE__ */ jsx2("svg", { className: "semiont-toast-icon", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx2("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) }),
  warning: /* @__PURE__ */ jsx2("svg", { className: "semiont-toast-icon", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx2("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" }) }),
  info: /* @__PURE__ */ jsx2("svg", { className: "semiont-toast-icon", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx2("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" }) })
};
function Toast({ toast, onClose }) {
  useEffect(() => {
    const timer = setTimeout(() => {
      onClose(toast.id);
    }, toast.duration || 3e3);
    return () => clearTimeout(timer);
  }, [toast, onClose]);
  return /* @__PURE__ */ jsxs(
    "div",
    {
      className: "semiont-toast",
      "data-variant": toast.type,
      role: "alert",
      children: [
        /* @__PURE__ */ jsx2("div", { className: "semiont-toast-icon-wrapper", children: icons[toast.type] }),
        /* @__PURE__ */ jsx2("p", { className: "semiont-toast-message", children: toast.message }),
        /* @__PURE__ */ jsx2(
          "button",
          {
            onClick: () => onClose(toast.id),
            className: "semiont-toast-close",
            "aria-label": "Close",
            children: /* @__PURE__ */ jsx2("svg", { className: "semiont-toast-close-icon", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx2("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) })
          }
        )
      ]
    }
  );
}
function ToastContainer({ toasts, onClose }) {
  const [mounted, setMounted] = useState(false);
  useEffect(() => {
    setMounted(true);
    return () => setMounted(false);
  }, []);
  if (!mounted) return null;
  return createPortal(
    /* @__PURE__ */ jsx2("div", { className: "semiont-toast-container", children: toasts.map((toast) => /* @__PURE__ */ jsx2(Toast, { toast, onClose }, toast.id)) }),
    document.body
  );
}
var ToastContext = React.createContext(void 0);
function ToastProvider({ children }) {
  const [toasts, setToasts] = useState([]);
  const showToast = React.useCallback((message, type = "info", duration) => {
    const id = Date.now().toString();
    const newToast = duration !== void 0 ? { id, message, type, duration } : { id, message, type };
    setToasts((prev) => [...prev, newToast]);
  }, []);
  const showSuccess = React.useCallback((message, duration) => showToast(message, "success", duration), [showToast]);
  const showError = React.useCallback((message, duration) => showToast(message, "error", duration), [showToast]);
  const showWarning = React.useCallback((message, duration) => showToast(message, "warning", duration), [showToast]);
  const showInfo = React.useCallback((message, duration) => showToast(message, "info", duration), [showToast]);
  const handleClose = React.useCallback((id) => {
    setToasts((prev) => prev.filter((toast) => toast.id !== id));
  }, []);
  const contextValue = React.useMemo(
    () => ({ showToast, showSuccess, showError, showWarning, showInfo }),
    [showToast, showSuccess, showError, showWarning, showInfo]
  );
  return /* @__PURE__ */ jsxs(ToastContext.Provider, { value: contextValue, children: [
    children,
    /* @__PURE__ */ jsx2(ToastContainer, { toasts, onClose: handleClose })
  ] });
}
function useToast() {
  const context = React.useContext(ToastContext);
  if (context === void 0) {
    throw new Error("useToast must be used within a ToastProvider");
  }
  return context;
}

// src/contexts/OpenResourcesContext.tsx
import { createContext as createContext2, useContext as useContext2 } from "react";
import { jsx as jsx3 } from "react/jsx-runtime";
var OpenResourcesContext = createContext2(void 0);
function OpenResourcesProvider({
  openResourcesManager,
  children
}) {
  return /* @__PURE__ */ jsx3(OpenResourcesContext.Provider, { value: openResourcesManager, children });
}
function useOpenResources() {
  const context = useContext2(OpenResourcesContext);
  if (context === void 0) {
    throw new Error("useOpenResources must be used within an OpenResourcesProvider");
  }
  return context;
}

// src/contexts/TranslationContext.tsx
import { createContext as createContext3, useContext as useContext3, useState as useState2, useEffect as useEffect2, useMemo } from "react";
import { Fragment, jsx as jsx4 } from "react/jsx-runtime";

// import("../../translations/**/*.json") in src/contexts/TranslationContext.tsx
var globImport_translations_json = __glob({
  "../../translations/ar.json": () => import("./ar-R4CRNXEF.mjs"),
  "../../translations/bn.json": () => import("./bn-CZKGRHTA.mjs"),
  "../../translations/cs.json": () => import("./cs-4WIB2IHH.mjs"),
  "../../translations/da.json": () => import("./da-JWYEUYPX.mjs"),
  "../../translations/de.json": () => import("./de-GWUQZGER.mjs"),
  "../../translations/el.json": () => import("./el-DM2GT7P5.mjs"),
  "../../translations/en.json": () => import("./en-IUV4ZXKH.mjs"),
  "../../translations/es.json": () => import("./es-6LVQIM3D.mjs"),
  "../../translations/fa.json": () => import("./fa-IRUJY3QI.mjs"),
  "../../translations/fi.json": () => import("./fi-53FBOEVT.mjs"),
  "../../translations/fr.json": () => import("./fr-Q5KY7QL6.mjs"),
  "../../translations/he.json": () => import("./he-HJNKULBY.mjs"),
  "../../translations/hi.json": () => import("./hi-UYZ4X6CR.mjs"),
  "../../translations/id.json": () => import("./id-UAQMH6U2.mjs"),
  "../../translations/it.json": () => import("./it-C7QEBNFA.mjs"),
  "../../translations/ja.json": () => import("./ja-THS6AOSJ.mjs"),
  "../../translations/ko.json": () => import("./ko-XKK3TWQG.mjs"),
  "../../translations/ms.json": () => import("./ms-GSK7LIF7.mjs"),
  "../../translations/nl.json": () => import("./nl-KUBWITGY.mjs"),
  "../../translations/no.json": () => import("./no-ECWZUHT6.mjs"),
  "../../translations/pl.json": () => import("./pl-PLVWSZWS.mjs"),
  "../../translations/pt.json": () => import("./pt-AL74ZTKB.mjs"),
  "../../translations/ro.json": () => import("./ro-WTPHLHGS.mjs"),
  "../../translations/sv.json": () => import("./sv-QCLI7SG4.mjs"),
  "../../translations/th.json": () => import("./th-WCKVZU6U.mjs"),
  "../../translations/tr.json": () => import("./tr-2CAFS2XS.mjs"),
  "../../translations/uk.json": () => import("./uk-TDE4JLCY.mjs"),
  "../../translations/vi.json": () => import("./vi-KKXZ4PCX.mjs"),
  "../../translations/zh.json": () => import("./zh-VH4XN5PV.mjs")
});

// src/contexts/TranslationContext.tsx
var TranslationContext = createContext3(null);
var translationCache = /* @__PURE__ */ new Map();
function processPluralFormat(text, params) {
  const pluralMatch = text.match(/\{(\w+),\s*plural,\s*/);
  if (!pluralMatch) {
    return text;
  }
  const paramName = pluralMatch[1];
  const count = params[paramName];
  if (count === void 0) {
    return text;
  }
  let startPos = pluralMatch[0].length;
  let braceCount = 1;
  let endPos = startPos;
  for (let i = startPos; i < text.length; i++) {
    if (text[i] === "{") braceCount++;
    else if (text[i] === "}") {
      braceCount--;
      if (braceCount === 0) {
        endPos = i;
        break;
      }
    }
  }
  const pluralCases = text.substring(startPos, endPos);
  const cases = {};
  const caseRegex = /(?:=(\d+)|(\w+))\s*\{([^}]+)\}/g;
  let caseMatch;
  while ((caseMatch = caseRegex.exec(pluralCases)) !== null) {
    const [, exactNumber, keyword, textContent] = caseMatch;
    const key = exactNumber !== void 0 ? `=${exactNumber}` : keyword;
    cases[key] = textContent;
  }
  const exactMatch = cases[`=${count}`];
  if (exactMatch !== void 0) {
    const result = exactMatch.replace(/#/g, String(count));
    return text.substring(0, pluralMatch.index) + result + text.substring(endPos + 1);
  }
  const otherCase = cases["other"];
  if (otherCase !== void 0) {
    const result = otherCase.replace(/#/g, String(count));
    return text.substring(0, pluralMatch.index) + result + text.substring(endPos + 1);
  }
  return text;
}
var AVAILABLE_LOCALES = [
  "ar",
  // Arabic
  "bn",
  // Bengali
  "cs",
  // Czech
  "da",
  // Danish
  "de",
  // German
  "el",
  // Greek
  "en",
  // English
  "es",
  // Spanish
  "fa",
  // Persian/Farsi
  "fi",
  // Finnish
  "fr",
  // French
  "he",
  // Hebrew
  "hi",
  // Hindi
  "id",
  // Indonesian
  "it",
  // Italian
  "ja",
  // Japanese
  "ko",
  // Korean
  "ms",
  // Malay
  "nl",
  // Dutch
  "no",
  // Norwegian
  "pl",
  // Polish
  "pt",
  // Portuguese
  "ro",
  // Romanian
  "sv",
  // Swedish
  "th",
  // Thai
  "tr",
  // Turkish
  "uk",
  // Ukrainian
  "vi",
  // Vietnamese
  "zh"
  // Chinese
];
async function loadTranslations(locale) {
  if (translationCache.has(locale)) {
    return translationCache.get(locale);
  }
  if (locale === "en") {
    translationCache.set("en", en_default);
    return en_default;
  }
  try {
    const translations = await globImport_translations_json(`../../translations/${locale}.json`);
    const translationData = translations.default || translations;
    translationCache.set(locale, translationData);
    return translationData;
  } catch (error) {
    console.error(`Failed to load translations for locale: ${locale}`, error);
    return en_default;
  }
}
var defaultTranslationManager = {
  t: (namespace, key, params) => {
    const translations = en_default;
    const translation = translations[namespace]?.[key];
    if (!translation) {
      console.warn(`Translation not found for ${namespace}.${key}`);
      return `${namespace}.${key}`;
    }
    if (params && typeof translation === "string") {
      let result = translation;
      result = processPluralFormat(result, params);
      Object.entries(params).forEach(([paramKey, paramValue]) => {
        result = result.replace(new RegExp(`\\{${paramKey}\\}`, "g"), String(paramValue));
      });
      return result;
    }
    return translation;
  }
};
function TranslationProvider({
  translationManager,
  locale,
  loadingComponent = null,
  children
}) {
  const [loadedTranslations, setLoadedTranslations] = useState2(null);
  const [isLoading, setIsLoading] = useState2(false);
  useEffect2(() => {
    if (locale && !translationManager) {
      setIsLoading(true);
      loadTranslations(locale).then((translations) => {
        setLoadedTranslations(translations);
        setIsLoading(false);
      }).catch((error) => {
        console.error("Failed to load translations:", error);
        setLoadedTranslations(en_default);
        setIsLoading(false);
      });
    }
  }, [locale, translationManager]);
  const localeManager = useMemo(() => {
    if (!loadedTranslations) return null;
    return {
      t: (namespace, key, params) => {
        const translation = loadedTranslations[namespace]?.[key];
        if (!translation) {
          console.warn(`Translation not found for ${namespace}.${key} in locale ${locale}`);
          return `${namespace}.${key}`;
        }
        if (params && typeof translation === "string") {
          let result = translation;
          result = processPluralFormat(result, params);
          Object.entries(params).forEach(([paramKey, paramValue]) => {
            result = result.replace(new RegExp(`\\{${paramKey}\\}`, "g"), String(paramValue));
          });
          return result;
        }
        return translation;
      }
    };
  }, [loadedTranslations, locale]);
  if (translationManager) {
    return /* @__PURE__ */ jsx4(TranslationContext.Provider, { value: translationManager, children });
  }
  if (locale && isLoading) {
    return /* @__PURE__ */ jsx4(Fragment, { children: loadingComponent });
  }
  if (locale && localeManager) {
    return /* @__PURE__ */ jsx4(TranslationContext.Provider, { value: localeManager, children });
  }
  return /* @__PURE__ */ jsx4(TranslationContext.Provider, { value: defaultTranslationManager, children });
}
function useTranslations(namespace) {
  const context = useContext3(TranslationContext);
  if (!context) {
    return (key, params) => {
      const translations = en_default;
      const translation = translations[namespace]?.[key];
      if (!translation) {
        console.warn(`Translation not found for ${namespace}.${key}`);
        return `${namespace}.${key}`;
      }
      if (params && typeof translation === "string") {
        let result = translation;
        result = processPluralFormat(result, params);
        Object.entries(params).forEach(([paramKey, paramValue]) => {
          result = result.replace(new RegExp(`\\{${paramKey}\\}`, "g"), String(paramValue));
        });
        return result;
      }
      return translation;
    };
  }
  return (key, params) => context.t(namespace, key, params);
}
function usePreloadTranslations() {
  return {
    preload: async (locale) => {
      try {
        await loadTranslations(locale);
        return true;
      } catch (error) {
        console.error(`Failed to preload translations for ${locale}:`, error);
        return false;
      }
    },
    isLoaded: (locale) => translationCache.has(locale)
  };
}

export {
  SessionProvider,
  useSessionContext,
  ToastContainer,
  ToastProvider,
  useToast,
  OpenResourcesProvider,
  useOpenResources,
  AVAILABLE_LOCALES,
  TranslationProvider,
  useTranslations,
  usePreloadTranslations
};
//# sourceMappingURL=chunk-OL5UST25.mjs.map