"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 {
  Users,
  Handshake,
  Clock,
  History,
  Paperclip,
  Plus
} from "lucide-react";
const LEGACY_TAB_MAP = {
  notes: "people",
  activities: "activity-log",
  addresses: "people",
  tasks: "people",
  dashboard: "people",
  "dane-firmy": "people",
  analysis: "people"
};
function resolveLegacyTab(tab) {
  if (!tab) return "people";
  if (LEGACY_TAB_MAP[tab]) return LEGACY_TAB_MAP[tab];
  return tab;
}
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 CountBadge({ count }) {
  if (count <= 0) return null;
  return /* @__PURE__ */ jsx("span", { className: "ml-1.5 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 CompanyDetailTabs({
  activeTab,
  onTabChange,
  injectedTabs = [],
  peopleCount = 0,
  dealsCount = 0,
  activitiesCount = 0,
  filesCount = 0,
  sectionAction = null,
  children
}) {
  const t = useT();
  const builtInTabs = React.useMemo(
    () => [
      {
        id: "people",
        label: t("customers.companies.detail.tabs.people", "People"),
        icon: /* @__PURE__ */ jsx(Users, { className: "size-4" }),
        badge: /* @__PURE__ */ jsx(CountBadge, { count: peopleCount })
      },
      {
        id: "deals",
        label: t("customers.companies.detail.tabs.deals", "Deals"),
        icon: /* @__PURE__ */ jsx(Handshake, { className: "size-4" }),
        badge: /* @__PURE__ */ jsx(CountBadge, { count: dealsCount })
      },
      {
        id: "activity-log",
        label: t("customers.companies.detail.tabs.activityLog", "Activity log"),
        icon: /* @__PURE__ */ jsx(Clock, { className: "size-4" }),
        badge: /* @__PURE__ */ jsx(CountBadge, { count: activitiesCount })
      },
      {
        id: "changelog",
        label: t("customers.companies.detail.tabs.changelog", "Changelog"),
        icon: /* @__PURE__ */ jsx(History, { className: "size-4" }),
        badge: /* @__PURE__ */ jsx(NewBadge, {})
      },
      {
        id: "files",
        label: t("customers.companies.detail.tabs.files", "Files"),
        icon: /* @__PURE__ */ jsx(Paperclip, { className: "size-4" }),
        badge: /* @__PURE__ */ jsx(CountBadge, { count: filesCount })
      }
    ],
    [t, peopleCount, dealsCount, activitiesCount, 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.companies.detail.tabs.label", "Company 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", role: "tabpanel", children })
  ] });
}
export {
  CompanyDetailTabs,
  resolveLegacyTab
};
//# sourceMappingURL=CompanyDetailTabs.js.map
