"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import Link from "next/link";
import { Button } from "../../ui/button";
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuLabel,
  DropdownMenuSeparator,
  DropdownMenuTrigger
} from "../../ui/dropdown-menu";
import { Plus, Loader2 } from "lucide-react";
import { useQuickCreateEntities } from "../../../hooks/useQuickCreateEntities";
import { createTestId, createCyId } from "../../../lib/test";
function QuickCreateDropdown() {
  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": "Loading quick create options",
          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": "Quick create",
        "data-testid": createTestId("topnav", "quick-create", "trigger"),
        "data-cy": createCyId("topnav", "quick-create-button"),
        children: /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4" })
      }
    ) }),
    /* @__PURE__ */ jsxs(
      DropdownMenuContent,
      {
        align: "start",
        className: "w-56",
        "data-testid": createTestId("topnav", "quick-create", "content"),
        "data-cy": createCyId("topnav", "quick-create-dropdown"),
        children: [
          /* @__PURE__ */ jsx(DropdownMenuLabel, { children: "Quick Create" }),
          /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
          availableEntities.map((entity) => {
            var _a, _b;
            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-testid": createTestId("quick-create", entity.slug, "item"),
                "data-cy": createCyId("quick-create", `${entity.slug}-link`),
                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: ((_a = entity.names) == null ? void 0 : _a.singular) || entity.slug }),
                    /* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground", children: [
                      "Create new ",
                      (((_b = entity.names) == null ? void 0 : _b.singular) || entity.slug).toLowerCase()
                    ] })
                  ] })
                ]
              }
            ) }, entity.slug);
          })
        ]
      }
    )
  ] });
}
export {
  QuickCreateDropdown
};
