"use client";
import { jsx } from "react/jsx-runtime";
import * as React from "react";
import { usePathname } from "next/navigation";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import { apiCall } from "../utils/apiCall.js";
import { SectionPage } from "../section-page/index.js";
function SettingsPageWrapper({
  sections,
  requiredFeatures,
  children
}) {
  const t = useT();
  const pathname = usePathname();
  const [userFeatures, setUserFeatures] = React.useState(void 0);
  const [loading, setLoading] = React.useState(true);
  React.useEffect(() => {
    let cancelled = false;
    async function loadFeatures() {
      if (requiredFeatures.length === 0) {
        setUserFeatures(/* @__PURE__ */ new Set());
        setLoading(false);
        return;
      }
      try {
        const call = await apiCall("/api/auth/feature-check", {
          method: "POST",
          headers: { "content-type": "application/json" },
          body: JSON.stringify({ features: requiredFeatures })
        });
        if (cancelled) return;
        if (call.ok && Array.isArray(call.result?.granted)) {
          setUserFeatures(new Set(call.result.granted));
        } else {
          setUserFeatures(/* @__PURE__ */ new Set());
        }
      } catch {
        if (!cancelled) setUserFeatures(/* @__PURE__ */ new Set());
      } finally {
        if (!cancelled) setLoading(false);
      }
    }
    loadFeatures();
    return () => {
      cancelled = true;
    };
  }, [requiredFeatures]);
  if (loading) {
    return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center h-64", children: /* @__PURE__ */ jsx("div", { className: "text-muted-foreground", children: t("common.loading", "Loading...") }) });
  }
  return /* @__PURE__ */ jsx(
    SectionPage,
    {
      title: "Settings",
      titleKey: "backend.nav.settings",
      sections,
      activePath: pathname ?? "/backend/settings",
      userFeatures,
      children
    }
  );
}
export {
  SettingsPageWrapper
};
//# sourceMappingURL=SettingsPageWrapper.js.map
