"use client";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { useState, useCallback, useMemo } from "react";
import { cn } from "../../../lib/utils/index.js";
import { useUserProfile } from "../../../hooks/useUserProfile.js";
import { usePrefetchSettings } from "../../../hooks/usePrefetch.js";
import {
  User,
  Users,
  Lock,
  Shield,
  Bell,
  CreditCard,
  Settings,
  Key,
  Share2
} from "lucide-react";
import { createAriaLabel, sel } from "../../../lib/test/index.js";
import { useTranslations } from "next-intl";
import { getEnabledSettingsPages } from "../../../lib/config/index.js";
const settingsIcons = {
  profile: User,
  password: Lock,
  security: Shield,
  notifications: Bell,
  "api-keys": Key,
  billing: CreditCard,
  "social-media": Share2,
  teams: Users,
  plans: CreditCard
};
function SettingsSidebar({ className }) {
  const pathname = usePathname();
  const [statusMessage, setStatusMessage] = useState("");
  const { hasPassword } = useUserProfile();
  const { prefetchProfile, prefetchTeams } = usePrefetchSettings();
  const t = useTranslations("common");
  const tSettings = useTranslations("settings");
  const getPrefetchHandler = useCallback((pageName) => {
    switch (pageName) {
      case "profile":
        return prefetchProfile;
      case "teams":
        return prefetchTeams;
      default:
        return void 0;
    }
  }, [prefetchProfile, prefetchTeams]);
  const filteredNavigation = useMemo(() => {
    const enabledPages = getEnabledSettingsPages();
    console.log("[SettingsSidebar] enabledPages:", enabledPages);
    return enabledPages.filter((page) => {
      if (page.key === "password" && !hasPassword) {
        return false;
      }
      return true;
    }).map((page) => ({
      name: page.key,
      href: `/dashboard/settings/${page.key}`,
      icon: settingsIcons[page.key],
      label: tSettings(`navigation.${page.key}`),
      description: tSettings(`overview.${page.key}Description`),
      order: page.order
    }));
  }, [hasPassword]);
  const handleNavigation = useCallback((itemName, itemDescription) => {
    setStatusMessage(`Navegando a ${itemName} - ${itemDescription}`);
  }, []);
  const handleKeyDown = useCallback((e, href, itemName, itemDescription) => {
    if (e.key === "Enter" || e.key === " ") {
      e.preventDefault();
      setStatusMessage(`Navegando a ${itemName} - ${itemDescription}`);
    }
  }, []);
  return /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx(
      "div",
      {
        "aria-live": "polite",
        "aria-atomic": "true",
        className: "sr-only",
        children: statusMessage
      }
    ),
    /* @__PURE__ */ jsx(
      "nav",
      {
        className: cn("space-y-2", className),
        role: "navigation",
        "aria-label": "Navegaci\xF3n de configuraci\xF3n",
        "data-cy": sel("settings.sidebar.container"),
        children: /* @__PURE__ */ jsxs("div", { className: "px-3 py-2", children: [
          /* @__PURE__ */ jsxs(
            "header",
            {
              className: "flex items-center gap-2 mb-4",
              "data-cy": sel("settings.sidebar.header"),
              children: [
                /* @__PURE__ */ jsx(
                  Settings,
                  {
                    className: "h-5 w-5 text-muted-foreground",
                    "aria-hidden": "true"
                  }
                ),
                /* @__PURE__ */ jsx(
                  "h2",
                  {
                    id: "settings-heading",
                    className: "text-lg font-semibold tracking-tight",
                    children: t("navigation.settings")
                  }
                )
              ]
            }
          ),
          /* @__PURE__ */ jsx(
            "section",
            {
              "aria-labelledby": "settings-heading",
              children: /* @__PURE__ */ jsx(
                "div",
                {
                  className: "space-y-1",
                  role: "list",
                  "data-cy": sel("settings.sidebar.nav.items"),
                  children: filteredNavigation.map((item) => {
                    const isActive = pathname === item.href;
                    const Icon = item.icon;
                    const prefetchHandler = getPrefetchHandler(item.name);
                    return /* @__PURE__ */ jsxs(
                      Link,
                      {
                        href: item.href,
                        role: "listitem",
                        onClick: () => handleNavigation(tSettings(`navigation.${item.name}`), tSettings(`overview.${item.name}Description`)),
                        onKeyDown: (e) => handleKeyDown(e, item.href, tSettings(`navigation.${item.name}`), tSettings(`overview.${item.name}Description`)),
                        onMouseEnter: prefetchHandler,
                        "aria-current": isActive ? "page" : void 0,
                        "aria-label": createAriaLabel(
                          "{name} - {description}{current}",
                          {
                            name: tSettings(`navigation.${item.name}`),
                            description: tSettings(`overview.${item.name}Description`),
                            current: isActive ? " (p\xE1gina actual)" : ""
                          }
                        ),
                        className: cn(
                          "flex items-center gap-3 rounded-lg px-3 py-2 text-sm transition-all hover:text-accent-foreground group focus:outline-none focus:ring-2 focus:ring-accent",
                          isActive ? "bg-accent text-accent-foreground" : "text-muted-foreground hover:bg-accent/50"
                        ),
                        "data-cy": sel("settings.sidebar.nav.item", { section: item.name.toLowerCase() }),
                        "data-nav-item": item.name.toLowerCase(),
                        "data-active": isActive,
                        children: [
                          /* @__PURE__ */ jsx(
                            Icon,
                            {
                              className: cn(
                                "h-4 w-4 transition-colors",
                                isActive ? "text-accent-foreground" : "text-muted-foreground group-hover:text-accent-foreground"
                              ),
                              "aria-hidden": "true"
                            }
                          ),
                          /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
                            /* @__PURE__ */ jsx(
                              "span",
                              {
                                className: cn(
                                  "font-medium transition-colors",
                                  isActive ? "text-accent-foreground" : "text-foreground"
                                ),
                                children: tSettings(`navigation.${item.name}`)
                              }
                            ),
                            /* @__PURE__ */ jsx(
                              "span",
                              {
                                className: cn(
                                  "text-xs transition-colors",
                                  isActive ? "text-accent-foreground/70" : "text-muted-foreground"
                                ),
                                children: tSettings(`overview.${item.name}Description`)
                              }
                            )
                          ] })
                        ]
                      },
                      item.name
                    );
                  })
                }
              )
            }
          )
        ] })
      }
    )
  ] });
}
export {
  SettingsSidebar
};
