"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import Link from "next/link";
import { Button } from "../../ui/button.js";
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuLabel,
  DropdownMenuSeparator,
  DropdownMenuTrigger
} from "../../ui/dropdown-menu.js";
import { Plus, Loader2 } from "lucide-react";
import { useQuickCreateEntities } from "../../../hooks/useQuickCreateEntities.js";
import { sel } from "../../../lib/test/index.js";
import { useTranslations } from "next-intl";
function capitalize(str) {
  return str.charAt(0).toUpperCase() + str.slice(1);
}
function QuickCreateDropdown() {
  const t = useTranslations("navigation");
  const { entities: availableEntities, isLoading, hasEntities } = useQuickCreateEntities();
  if (isLoading || !hasEntities) {
    if (isLoading) {
      return /* @__PURE__ */ jsx(
        Button,
        {
          variant: "ghost",
          size: "icon",
          className: "relative h-8 w-8",
          disabled: true,
          "aria-label": t("quickCreate"),
          children: /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin" })
        }
      );
    }
    return null;
  }
  return /* @__PURE__ */ jsxs(DropdownMenu, { children: [
    /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
      Button,
      {
        variant: "ghost",
        size: "icon",
        className: "relative h-8 w-8",
        "aria-label": t("quickCreate"),
        "data-cy": sel("dashboard.topnav.quickCreate.trigger"),
        children: /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4" })
      }
    ) }),
    /* @__PURE__ */ jsxs(
      DropdownMenuContent,
      {
        align: "start",
        className: "w-56",
        "data-cy": sel("dashboard.topnav.quickCreate.content"),
        children: [
          /* @__PURE__ */ jsx(DropdownMenuLabel, { children: t("quickCreate") }),
          /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
          availableEntities.map((entity) => {
            var _a;
            const entityName = capitalize(((_a = entity.names) == null ? void 0 : _a.singular) || entity.slug);
            return /* @__PURE__ */ jsx(DropdownMenuItem, { asChild: true, children: /* @__PURE__ */ jsxs(
              Link,
              {
                href: `/dashboard/${entity.slug}/create`,
                className: "flex items-center gap-3 w-full cursor-pointer",
                "data-cy": sel("dashboard.topnav.quickCreate.link", { slug: entity.slug }),
                children: [
                  /* @__PURE__ */ jsx(entity.icon, { className: "h-4 w-4" }),
                  /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
                    /* @__PURE__ */ jsx("span", { className: "font-medium", children: entityName }),
                    /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: t("quickCreateNew", { entity: entityName }) })
                  ] })
                ]
              }
            ) }, entity.slug);
          })
        ]
      }
    )
  ] });
}
export {
  QuickCreateDropdown
};
