"use client";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import { useAuth } from "../../../hooks/useAuth";
import {
  Sheet,
  SheetContent,
  SheetHeader,
  SheetTitle,
  SheetDescription
} from "../../ui/sheet";
import { Button } from "../../ui/button";
import { Separator } from "../../ui/separator";
import Link from "next/link";
import { Shield, LogOut } from "lucide-react";
import { createTestId, createCyId } from "../../../lib/test";
import { TeamSwitcherCompact } from "../../teams/TeamSwitcherCompact";
import { useTranslations } from "next-intl";
import { useIsSuperAdmin } from "../../app/guards/SuperAdminGuard";
import { useState } from "react";
import { MOBILE_NAV_CONFIG } from "../../../lib/config/config-sync";
import { getIcon } from "../../../lib/config/icon-map";
function MobileMoreSheet({ isOpen, onOpenChange }) {
  const { user, signOut } = useAuth();
  const tCommon = useTranslations("common");
  const t = useTranslations();
  const isSuperAdmin = useIsSuperAdmin();
  const [isSigningOut, setIsSigningOut] = useState(false);
  const handleSignOut = async () => {
    try {
      setIsSigningOut(true);
      await signOut();
      onOpenChange(false);
    } catch (error) {
      console.error("Error signing out:", error);
    } finally {
      setIsSigningOut(false);
    }
  };
  const handleLinkClick = () => {
    onOpenChange(false);
  };
  const menuItems = MOBILE_NAV_CONFIG.moreSheetItems.filter((item) => item.enabled).map((configItem) => {
    const IconComponent = getIcon(configItem.icon);
    return {
      id: configItem.id,
      label: t(configItem.labelKey),
      href: configItem.href,
      icon: IconComponent,
      external: configItem.external || false
    };
  });
  if (!user) return null;
  return /* @__PURE__ */ jsx(Sheet, { open: isOpen, onOpenChange, children: /* @__PURE__ */ jsxs(
    SheetContent,
    {
      side: "bottom",
      className: "rounded-t-[20px]",
      ...createTestId("mobile-more-sheet", "content") && { "data-testid": createTestId("mobile-more-sheet", "content") },
      ...createCyId("mobile-more-sheet", "content") && { "data-cy": createCyId("mobile-more-sheet", "content") },
      children: [
        /* @__PURE__ */ jsxs(SheetHeader, { children: [
          /* @__PURE__ */ jsx(SheetTitle, { children: tCommon("mobileNav.moreOptions") }),
          /* @__PURE__ */ jsx(SheetDescription, { children: tCommon("mobileNav.moreOptionsDescription") })
        ] }),
        /* @__PURE__ */ jsxs("div", { className: "mt-6 space-y-2", children: [
          menuItems.map((item) => {
            const Icon = item.icon;
            return /* @__PURE__ */ jsxs(
              Link,
              {
                href: item.href,
                onClick: handleLinkClick,
                className: "flex items-center gap-3 px-4 py-3 rounded-lg hover:bg-accent transition-colors",
                target: item.external ? "_blank" : void 0,
                rel: item.external ? "noopener noreferrer" : void 0,
                ...createTestId("mobile-more-sheet", "item", item.id) && { "data-testid": createTestId("mobile-more-sheet", "item", item.id) },
                ...createCyId("mobile-more-sheet", `item-${item.id}`) && { "data-cy": createCyId("mobile-more-sheet", `item-${item.id}`) },
                children: [
                  /* @__PURE__ */ jsx(Icon, { className: "h-5 w-5 text-muted-foreground", "aria-hidden": "true" }),
                  /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: item.label })
                ]
              },
              item.id
            );
          }),
          isSuperAdmin && /* @__PURE__ */ jsxs(Fragment, { children: [
            /* @__PURE__ */ jsx(Separator, { className: "my-2" }),
            /* @__PURE__ */ jsxs(
              Link,
              {
                href: "/superadmin",
                onClick: handleLinkClick,
                className: "flex items-center gap-3 px-4 py-3 rounded-lg hover:bg-red-50 text-red-600 transition-colors",
                ...createTestId("mobile-more-sheet", "superadmin") && { "data-testid": createTestId("mobile-more-sheet", "superadmin") },
                ...createCyId("mobile-more-sheet", "superadmin-link") && { "data-cy": createCyId("mobile-more-sheet", "superadmin-link") },
                children: [
                  /* @__PURE__ */ jsx(Shield, { className: "h-5 w-5", "aria-hidden": "true" }),
                  /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: "Super Admin Panel" })
                ]
              }
            )
          ] }),
          /* @__PURE__ */ jsx(Separator, { className: "my-2" }),
          /* @__PURE__ */ jsx(
            "div",
            {
              ...createTestId("mobile-more-sheet", "team-switcher") && { "data-testid": createTestId("mobile-more-sheet", "team-switcher") },
              ...createCyId("mobile-more-sheet", "team-switcher") && { "data-cy": createCyId("mobile-more-sheet", "team-switcher") },
              children: /* @__PURE__ */ jsx(TeamSwitcherCompact, { className: "border-0 p-0" })
            }
          ),
          /* @__PURE__ */ jsx(Separator, { className: "my-4" }),
          /* @__PURE__ */ jsxs(
            Button,
            {
              variant: "ghost",
              onClick: handleSignOut,
              disabled: isSigningOut,
              className: "w-full justify-start gap-3 px-4 py-3 h-auto text-red-600 hover:text-red-700 hover:bg-red-50",
              ...createTestId("mobile-more-sheet", "signout") && { "data-testid": createTestId("mobile-more-sheet", "signout") },
              ...createCyId("mobile-more-sheet", "signout-button") && { "data-cy": createCyId("mobile-more-sheet", "signout-button") },
              children: [
                /* @__PURE__ */ jsx(LogOut, { className: "h-5 w-5", "aria-hidden": "true" }),
                /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: isSigningOut ? tCommon("buttons.signingOut") : tCommon("buttons.signOut") })
              ]
            }
          )
        ] })
      ]
    }
  ) });
}
export {
  MobileMoreSheet
};
