"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import * as React from "react";
import { cn } from "@open-mercato/shared/lib/utils";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import { Button } from "@open-mercato/ui/primitives/button";
import {
  SquareCheckBig,
  Mail,
  Briefcase,
  Building2,
  Check,
  History,
  Paperclip,
  Plus,
  MapPin
} from "lucide-react";
const SUPPORTED_TAB_IDS = /* @__PURE__ */ new Set(["activities", "emails", "deals", "companies", "addresses", "tasks", "changelog", "files"]);
function resolveLegacyTab(tab) {
  if (!tab) return "activities";
  return SUPPORTED_TAB_IDS.has(tab) ? tab : "activities";
}
function CountBadge({ count }) {
  if (count <= 0) return null;
  return /* @__PURE__ */ jsx("span", { className: "ml-1 rounded-full bg-muted px-1.5 py-0.5 text-xs font-medium leading-none text-muted-foreground", children: count > 999 ? "999+" : count });
}
function NewBadge() {
  return /* @__PURE__ */ jsx("span", { className: "ml-1.5 rounded bg-foreground px-1.5 py-0.5 text-overline font-semibold leading-none text-background", children: "NEW" });
}
function PersonDetailTabs({
  activeTab,
  onTabChange,
  injectedTabs = [],
  activitiesCount = 0,
  dealsCount = 0,
  companiesCount = 0,
  addressesCount = 0,
  tasksCount = 0,
  filesCount = 0,
  sectionAction = null,
  children
}) {
  const t = useT();
  const builtInTabs = React.useMemo(
    () => [
      {
        id: "activities",
        label: t("customers.people.detail.tabs.activities", "Activities"),
        icon: /* @__PURE__ */ jsx(SquareCheckBig, { className: "size-4" }),
        badge: /* @__PURE__ */ jsx(CountBadge, { count: activitiesCount })
      },
      {
        id: "emails",
        label: t("customers.people.detail.tabs.emails", "Emails"),
        icon: /* @__PURE__ */ jsx(Mail, { className: "size-4" })
      },
      {
        id: "deals",
        label: t("customers.people.detail.tabs.deals", "Deals"),
        icon: /* @__PURE__ */ jsx(Briefcase, { className: "size-4" }),
        badge: /* @__PURE__ */ jsx(CountBadge, { count: dealsCount })
      },
      {
        id: "companies",
        label: t("customers.people.detail.tabs.companies", "Companies"),
        icon: /* @__PURE__ */ jsx(Building2, { className: "size-4" }),
        badge: /* @__PURE__ */ jsx(CountBadge, { count: companiesCount })
      },
      {
        id: "addresses",
        label: t("customers.people.detail.tabs.addresses", "Addresses"),
        icon: /* @__PURE__ */ jsx(MapPin, { className: "size-4" }),
        badge: /* @__PURE__ */ jsx(CountBadge, { count: addressesCount })
      },
      {
        id: "tasks",
        label: t("customers.people.detail.tabs.tasks", "Tasks"),
        icon: /* @__PURE__ */ jsx(Check, { className: "size-4" }),
        badge: /* @__PURE__ */ jsx(CountBadge, { count: tasksCount })
      },
      {
        id: "changelog",
        label: t("customers.people.detail.tabs.changelog", "Change log"),
        icon: /* @__PURE__ */ jsx(History, { className: "size-4" }),
        badge: /* @__PURE__ */ jsx(NewBadge, {})
      },
      {
        id: "files",
        label: t("customers.people.detail.tabs.files", "Files"),
        icon: /* @__PURE__ */ jsx(Paperclip, { className: "size-4" }),
        badge: /* @__PURE__ */ jsx(CountBadge, { count: filesCount })
      }
    ],
    [t, activitiesCount, dealsCount, companiesCount, addressesCount, tasksCount, filesCount]
  );
  const allTabs = React.useMemo(
    () => [
      ...builtInTabs,
      ...injectedTabs.map((tab) => ({
        id: tab.id,
        label: tab.label
      }))
    ],
    [builtInTabs, injectedTabs]
  );
  return /* @__PURE__ */ jsxs("div", { children: [
    /* @__PURE__ */ jsxs("div", { className: "flex items-end justify-between gap-2 border-b", role: "tablist", "aria-label": t("customers.people.detail.tabs.label", "Person detail sections"), children: [
      /* @__PURE__ */ jsx("nav", { className: "-mb-px flex flex-1 gap-1 overflow-x-auto px-1", children: allTabs.map((tab) => {
        const isActive = activeTab === tab.id;
        return /* @__PURE__ */ jsxs(
          Button,
          {
            type: "button",
            variant: "ghost",
            size: "sm",
            role: "tab",
            "aria-selected": isActive,
            onClick: () => onTabChange(tab.id),
            className: cn(
              "h-auto shrink-0 rounded-none border-b-2 px-3 py-2.5 hover:bg-transparent",
              isActive ? "border-foreground text-foreground font-semibold" : "border-transparent text-muted-foreground hover:text-foreground"
            ),
            children: [
              tab.icon && /* @__PURE__ */ jsx("span", { className: "mr-1.5", children: tab.icon }),
              tab.label,
              tab.badge
            ]
          },
          tab.id
        );
      }) }),
      sectionAction ? /* @__PURE__ */ jsxs(
        Button,
        {
          type: "button",
          size: "sm",
          onClick: sectionAction.onClick,
          disabled: sectionAction.disabled,
          className: "mb-1.5 mr-1 shrink-0",
          children: [
            /* @__PURE__ */ jsx(Plus, { className: "mr-1.5 h-4 w-4" }),
            sectionAction.label
          ]
        }
      ) : null
    ] }),
    /* @__PURE__ */ jsx("div", { className: "pt-6", children })
  ] });
}
export {
  PersonDetailTabs,
  resolveLegacyTab
};
//# sourceMappingURL=PersonDetailTabs.js.map
