'use client';
import {
  en_default
} from "./chunk-BHAP6MVA.mjs";
import {
  __glob
} from "./chunk-3JTO27MH.mjs";

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

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

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

// src/contexts/TranslationContext.tsx
import { createContext as createContext4, useContext as useContext4, useState, useEffect, 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-TQSFB35U.mjs"),
  "../../translations/bn.json": () => import("./bn-525U24T3.mjs"),
  "../../translations/cs.json": () => import("./cs-OYWTGLFM.mjs"),
  "../../translations/da.json": () => import("./da-BDXG2ITK.mjs"),
  "../../translations/de.json": () => import("./de-NB5JLMES.mjs"),
  "../../translations/el.json": () => import("./el-3SVXEAJI.mjs"),
  "../../translations/en.json": () => import("./en-DVB4OE2R.mjs"),
  "../../translations/es.json": () => import("./es-YBOFA3W5.mjs"),
  "../../translations/fa.json": () => import("./fa-7MU36AMY.mjs"),
  "../../translations/fi.json": () => import("./fi-PQKJB32G.mjs"),
  "../../translations/fr.json": () => import("./fr-U4HK5GM6.mjs"),
  "../../translations/he.json": () => import("./he-F5MNZHAL.mjs"),
  "../../translations/hi.json": () => import("./hi-2PHI37ZX.mjs"),
  "../../translations/id.json": () => import("./id-JPRBNCGS.mjs"),
  "../../translations/it.json": () => import("./it-MRLWI5OS.mjs"),
  "../../translations/ja.json": () => import("./ja-YQ6RPI2T.mjs"),
  "../../translations/ko.json": () => import("./ko-DUAVCEXX.mjs"),
  "../../translations/ms.json": () => import("./ms-FBHSR4PG.mjs"),
  "../../translations/nl.json": () => import("./nl-IC2MPZXN.mjs"),
  "../../translations/no.json": () => import("./no-LLD43NRM.mjs"),
  "../../translations/pl.json": () => import("./pl-DDOJBR4D.mjs"),
  "../../translations/pt.json": () => import("./pt-7TFHQRRN.mjs"),
  "../../translations/ro.json": () => import("./ro-P4PJEGDU.mjs"),
  "../../translations/sv.json": () => import("./sv-LF3VEQD2.mjs"),
  "../../translations/th.json": () => import("./th-YUQAOFXF.mjs"),
  "../../translations/tr.json": () => import("./tr-CSIGLMJC.mjs"),
  "../../translations/uk.json": () => import("./uk-LW3QBKSR.mjs"),
  "../../translations/vi.json": () => import("./vi-W464Y6ZC.mjs"),
  "../../translations/zh.json": () => import("./zh-R5XLM3EI.mjs")
});

// src/contexts/TranslationContext.tsx
var TranslationContext = createContext4(null);
var translationCache = /* @__PURE__ */ new Map();
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;
      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] = useState(null);
  const [isLoading, setIsLoading] = useState(false);
  useEffect(() => {
    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;
          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 = useContext4(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;
        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)
  };
}

// src/components/Toast.tsx
import React4, { useEffect as useEffect2, useState as useState2 } from "react";
import { createPortal } from "react-dom";
import { jsx as jsx5, jsxs } from "react/jsx-runtime";
var icons = {
  success: /* @__PURE__ */ jsx5("svg", { className: "w-5 h-5", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx5("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M5 13l4 4L19 7" }) }),
  error: /* @__PURE__ */ jsx5("svg", { className: "w-5 h-5", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx5("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) }),
  warning: /* @__PURE__ */ jsx5("svg", { className: "w-5 h-5", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx5("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__ */ jsx5("svg", { className: "w-5 h-5", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx5("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" }) })
};
var styles = {
  success: "bg-green-50 dark:bg-green-900/20 text-green-800 dark:text-green-200 border-green-200 dark:border-green-800",
  error: "bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200 border-red-200 dark:border-red-800",
  warning: "bg-yellow-50 dark:bg-yellow-900/20 text-yellow-800 dark:text-yellow-200 border-yellow-200 dark:border-yellow-800",
  info: "bg-blue-50 dark:bg-blue-900/20 text-blue-800 dark:text-blue-200 border-blue-200 dark:border-blue-800"
};
function Toast({ toast, onClose }) {
  useEffect2(() => {
    const timer = setTimeout(() => {
      onClose(toast.id);
    }, toast.duration || 3e3);
    return () => clearTimeout(timer);
  }, [toast, onClose]);
  return /* @__PURE__ */ jsxs(
    "div",
    {
      className: `flex items-center gap-3 px-4 py-3 rounded-lg border shadow-lg transition-all duration-300 transform ${styles[toast.type]}`,
      role: "alert",
      children: [
        /* @__PURE__ */ jsx5("div", { className: "flex-shrink-0", children: icons[toast.type] }),
        /* @__PURE__ */ jsx5("p", { className: "text-sm font-medium", children: toast.message }),
        /* @__PURE__ */ jsx5(
          "button",
          {
            onClick: () => onClose(toast.id),
            className: "ml-auto flex-shrink-0 hover:opacity-70 transition-opacity",
            "aria-label": "Close",
            children: /* @__PURE__ */ jsx5("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx5("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) })
          }
        )
      ]
    }
  );
}
function ToastContainer({ toasts, onClose }) {
  const [mounted, setMounted] = useState2(false);
  useEffect2(() => {
    setMounted(true);
    return () => setMounted(false);
  }, []);
  if (!mounted) return null;
  return createPortal(
    /* @__PURE__ */ jsx5("div", { className: "fixed top-4 right-4 z-50 space-y-2 max-w-sm", children: toasts.map((toast) => /* @__PURE__ */ jsx5(Toast, { toast, onClose }, toast.id)) }),
    document.body
  );
}
var ToastContext = React4.createContext(void 0);
function ToastProvider({ children }) {
  const [toasts, setToasts] = useState2([]);
  const showToast = (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 = (message, duration) => showToast(message, "success", duration);
  const showError = (message, duration) => showToast(message, "error", duration);
  const showWarning = (message, duration) => showToast(message, "warning", duration);
  const showInfo = (message, duration) => showToast(message, "info", duration);
  const handleClose = (id) => {
    setToasts((prev) => prev.filter((toast) => toast.id !== id));
  };
  return /* @__PURE__ */ jsxs(ToastContext.Provider, { value: { showToast, showSuccess, showError, showWarning, showInfo }, children: [
    children,
    /* @__PURE__ */ jsx5(ToastContainer, { toasts, onClose: handleClose })
  ] });
}
function useToast() {
  const context = React4.useContext(ToastContext);
  if (context === void 0) {
    throw new Error("useToast must be used within a ToastProvider");
  }
  return context;
}

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