"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import { Check, X, Users } from "lucide-react";
import { Button } from "../../primitives/button.js";
import { IconButton } from "../../primitives/icon-button.js";
import { ViewChipMenu } from "./ViewChipMenu.js";
import { useT } from "@open-mercato/shared/lib/i18n/context";
function ViewChip({
  id,
  label,
  kind,
  isActive,
  disabled,
  isShared,
  isRenaming,
  renameValue,
  canApplyToRoles,
  deleting,
  onActivate,
  onRenameValueChange,
  onRenameConfirm,
  onRenameCancel,
  onRenameStart,
  onClone,
  onShareStart,
  onDelete
}) {
  const t = useT();
  if (isRenaming) {
    const renameTrimmed = renameValue.trim();
    return /* @__PURE__ */ jsxs("div", { className: "inline-flex items-center gap-1 rounded-md border border-primary bg-primary/5 px-3 h-8", children: [
      /* @__PURE__ */ jsx(
        "input",
        {
          value: renameValue,
          onChange: (e) => onRenameValueChange(e.target.value),
          className: "w-24 bg-transparent text-sm outline-none",
          autoFocus: true,
          onKeyDown: (e) => {
            if (e.key === "Enter") onRenameConfirm();
            if (e.key === "Escape") onRenameCancel();
          }
        }
      ),
      /* @__PURE__ */ jsx(
        IconButton,
        {
          type: "button",
          variant: "ghost",
          size: "xs",
          className: "h-auto",
          onClick: onRenameConfirm,
          disabled: !renameTrimmed,
          "aria-label": t("ui.perspectives.rename.confirm", "Confirm rename"),
          children: /* @__PURE__ */ jsx(Check, { className: `size-4 ${renameTrimmed ? "text-brand-violet" : "text-muted-foreground opacity-50"}` })
        }
      ),
      /* @__PURE__ */ jsx(
        IconButton,
        {
          type: "button",
          variant: "ghost",
          size: "xs",
          className: "h-auto",
          onClick: onRenameCancel,
          "aria-label": t("ui.perspectives.rename.cancel", "Cancel rename"),
          children: /* @__PURE__ */ jsx(X, { className: "size-4 text-muted-foreground hover:text-destructive" })
        }
      )
    ] });
  }
  const showUsersIcon = kind === "role" || isShared;
  return /* @__PURE__ */ jsxs(
    "div",
    {
      className: `inline-flex items-center gap-0.5 rounded-md border h-8 text-sm ${isActive ? "bg-brand-violet/10 border-brand-violet/30 font-medium text-brand-violet" : "border-border"}`,
      children: [
        /* @__PURE__ */ jsxs(
          Button,
          {
            type: "button",
            variant: "ghost",
            size: "sm",
            className: "h-auto px-3 py-0 text-sm hover:bg-transparent",
            onClick: onActivate,
            disabled,
            children: [
              showUsersIcon ? /* @__PURE__ */ jsx(Users, { className: "size-3 mr-1 opacity-50" }) : null,
              label
            ]
          }
        ),
        /* @__PURE__ */ jsx(
          ViewChipMenu,
          {
            kind,
            canApplyToRoles,
            deleting,
            onRenameStart,
            onClone,
            onShareStart,
            onDelete
          }
        )
      ]
    }
  );
}
export {
  ViewChip
};
//# sourceMappingURL=ViewChip.js.map
