"use client";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import * as React from "react";
import { Send } from "lucide-react";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import { Button } from "../../primitives/button.js";
import { IconButton } from "../../primitives/icon-button.js";
import {
  MessageComposer
} from "./MessageComposer.js";
function SendObjectMessageDialog({
  object,
  defaultValues,
  lockedType = "messages.defaultWithObjects",
  requiredActionConfig = null,
  disabled = false,
  buttonVariant = "ghost",
  buttonSize = "icon",
  buttonClassName,
  buttonLabel,
  viewHref: _viewHref = null,
  onSuccess
}) {
  const t = useT();
  const [open, setOpen] = React.useState(false);
  const label = buttonLabel ?? t("messages.compose", "Compose message");
  const openComposer = React.useCallback(() => {
    if (disabled) return;
    setOpen(true);
  }, [disabled]);
  const contextObject = React.useMemo(() => ({
    entityModule: object.entityModule,
    entityType: object.entityType,
    entityId: object.entityId,
    sourceEntityType: object.sourceEntityType ?? null,
    sourceEntityId: object.sourceEntityId ?? null,
    previewData: object.previewData ?? null
  }), [object.entityId, object.entityModule, object.entityType, object.sourceEntityId, object.sourceEntityType, object.previewData]);
  const trigger = buttonSize === "icon" && (buttonVariant === "outline" || buttonVariant === "ghost") ? /* @__PURE__ */ jsx(
    IconButton,
    {
      type: "button",
      size: "default",
      variant: buttonVariant,
      className: buttonClassName,
      disabled,
      onClick: openComposer,
      "aria-label": label,
      title: label,
      children: /* @__PURE__ */ jsx(Send, { className: "size-4" })
    }
  ) : /* @__PURE__ */ jsx(
    Button,
    {
      type: "button",
      size: buttonSize,
      variant: buttonVariant,
      className: buttonClassName,
      disabled,
      onClick: openComposer,
      "aria-label": label,
      title: label,
      children: /* @__PURE__ */ jsx(Send, { className: "size-4" })
    }
  );
  return /* @__PURE__ */ jsxs(Fragment, { children: [
    trigger,
    /* @__PURE__ */ jsx(
      MessageComposer,
      {
        variant: "compose",
        open,
        onOpenChange: setOpen,
        lockedType,
        contextObject,
        requiredActionConfig,
        defaultValues,
        onSuccess
      }
    )
  ] });
}
export {
  SendObjectMessageDialog
};
//# sourceMappingURL=SendObjectMessageDialog.js.map
