"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import * as React from "react";
import { Workflow } from "lucide-react";
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle
} from "@open-mercato/ui/primitives/dialog";
import { Button } from "@open-mercato/ui/primitives/button";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import { translateWithFallback } from "@open-mercato/shared/lib/i18n/translate";
function ChangeStageDialog({
  open,
  selectedCount,
  pipelineName,
  stages,
  isSubmitting,
  onClose,
  onConfirm
}) {
  const t = useT();
  const [draftStageId, setDraftStageId] = React.useState(stages[0]?.id ?? null);
  React.useEffect(() => {
    if (open) setDraftStageId(stages[0]?.id ?? null);
  }, [open, stages]);
  const handleConfirm = () => {
    if (draftStageId) onConfirm(draftStageId);
  };
  const handleKeyDown = (event) => {
    if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
      event.preventDefault();
      handleConfirm();
    }
  };
  return /* @__PURE__ */ jsx(
    Dialog,
    {
      open,
      onOpenChange: (next) => {
        if (!next && !isSubmitting) onClose();
      },
      children: /* @__PURE__ */ jsxs(DialogContent, { className: "sm:max-w-md", onKeyDown: handleKeyDown, children: [
        /* @__PURE__ */ jsxs(DialogHeader, { children: [
          /* @__PURE__ */ jsxs(DialogTitle, { className: "flex items-center gap-2", children: [
            /* @__PURE__ */ jsx(Workflow, { className: "size-4", "aria-hidden": "true" }),
            translateWithFallback(
              t,
              "customers.deals.kanban.bulk.changeStage.title",
              "Change stage for {count} deals",
              { count: selectedCount }
            )
          ] }),
          /* @__PURE__ */ jsx(DialogDescription, { children: translateWithFallback(
            t,
            "customers.deals.kanban.bulk.changeStage.context",
            "Pipeline: {pipeline}",
            { pipeline: pipelineName }
          ) })
        ] }),
        /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-1 py-1", children: stages.map((stage) => {
          const isSelected = draftStageId === stage.id;
          return /* @__PURE__ */ jsxs(
            Button,
            {
              variant: "ghost",
              type: "button",
              onClick: () => setDraftStageId(stage.id),
              className: `flex w-full items-center justify-between rounded-md px-3 py-2 text-sm transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ${isSelected ? "bg-muted" : ""}`,
              children: [
                /* @__PURE__ */ jsx("span", { className: "font-medium text-foreground", children: stage.label }),
                /* @__PURE__ */ jsx(
                  "span",
                  {
                    className: `inline-flex size-4 items-center justify-center rounded-full border ${isSelected ? "border-primary bg-primary" : "border-input"}`,
                    "aria-hidden": "true",
                    children: isSelected ? /* @__PURE__ */ jsx("span", { className: "size-1.5 rounded-full bg-primary-foreground" }) : null
                  }
                )
              ]
            },
            stage.id
          );
        }) }),
        /* @__PURE__ */ jsxs(DialogFooter, { children: [
          /* @__PURE__ */ jsx(Button, { variant: "outline", onClick: onClose, type: "button", disabled: isSubmitting, children: translateWithFallback(t, "customers.deals.kanban.filter.cancel", "Cancel") }),
          /* @__PURE__ */ jsx(
            Button,
            {
              type: "button",
              onClick: handleConfirm,
              disabled: !draftStageId || isSubmitting || stages.length === 0,
              children: translateWithFallback(
                t,
                "customers.deals.kanban.bulk.changeStage.confirm",
                "Move {count} deals",
                { count: selectedCount }
              )
            }
          )
        ] })
      ] })
    }
  );
}
var ChangeStageDialog_default = ChangeStageDialog;
export {
  ChangeStageDialog,
  ChangeStageDialog_default as default
};
//# sourceMappingURL=ChangeStageDialog.js.map
