"use client";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import * as React from "react";
import { Loader2 } from "lucide-react";
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@open-mercato/ui/primitives/dialog";
import { Button } from "@open-mercato/ui/primitives/button";
import {
  AppearanceSelector
} from "@open-mercato/core/modules/dictionaries/components/AppearanceSelector";
function AppearanceDialog({
  open,
  title,
  icon,
  color,
  labels,
  iconSuggestions,
  onIconChange,
  onColorChange,
  onSubmit,
  onClose,
  isSaving = false,
  errorMessage = null,
  primaryLabel,
  savingLabel,
  cancelLabel
}) {
  const handleSubmit = React.useCallback(() => {
    if (isSaving) return;
    onSubmit();
  }, [isSaving, onSubmit]);
  return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange: (next) => {
    if (!next) onClose();
  }, children: /* @__PURE__ */ jsxs(
    DialogContent,
    {
      className: "min-h-[70vh] sm:min-h-0 sm:max-w-md",
      onEscapeKeyDown: (event) => {
        event.preventDefault();
        onClose();
      },
      onKeyDown: (event) => {
        if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
          event.preventDefault();
          handleSubmit();
        }
      },
      children: [
        /* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: title }) }),
        /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col gap-4", children: [
          /* @__PURE__ */ jsx(
            AppearanceSelector,
            {
              icon,
              color,
              labels,
              iconSuggestions,
              onIconChange,
              onColorChange,
              disabled: isSaving
            }
          ),
          errorMessage ? /* @__PURE__ */ jsx("p", { className: "text-sm text-status-error-text", children: errorMessage }) : null
        ] }),
        /* @__PURE__ */ jsxs(DialogFooter, { children: [
          /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: onClose, disabled: isSaving, children: cancelLabel }),
          /* @__PURE__ */ jsx(Button, { type: "button", onClick: handleSubmit, disabled: isSaving, children: isSaving ? /* @__PURE__ */ jsxs(Fragment, { children: [
            /* @__PURE__ */ jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }),
            savingLabel
          ] }) : primaryLabel })
        ] })
      ]
    }
  ) });
}
export {
  AppearanceDialog
};
//# sourceMappingURL=AppearanceDialog.js.map
