"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import * as React from "react";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import { FormHeader } from "@open-mercato/ui/backend/forms";
import { IconButton } from "@open-mercato/ui/primitives/icon-button";
import {
  Archive,
  ArchiveRestore,
  ChevronDown,
  ChevronUp,
  FilePenLine,
  Forward,
  Mail,
  MailOpen,
  Reply,
  Trash2
} from "lucide-react";
import { formatDateTime } from "../utils.js";
function MessageHeader(props) {
  const t = useT();
  const showSubject = props.showSubject !== false;
  const canReply = !props.detail.isDraft && props.detail.typeDefinition.allowReply;
  const actionItems = React.useMemo(() => {
    const items = [];
    if (props.detail.isDraft && props.detail.canEditDraft) {
      items.push({
        id: "edit",
        label: t("messages.actions.edit", "Edit"),
        icon: FilePenLine,
        onSelect: props.onEdit
      });
    }
    if (!props.detail.isDraft && props.detail.typeDefinition.allowForward) {
      items.push({
        id: "forward",
        label: t("messages.forward", "Forward"),
        icon: Forward,
        onSelect: props.onForward
      });
    }
    if (!props.detail.isDraft) {
      items.push({
        id: "toggle-read",
        label: props.detail.isRead ? t("messages.actions.markUnread", "Mark unread") : t("messages.actions.markRead", "Mark read"),
        icon: props.detail.isRead ? Mail : MailOpen,
        onSelect: props.onToggleRead,
        disabled: props.updatingState
      });
    }
    if (!props.detail.isDraft && props.detail.canArchive) {
      items.push({
        id: "toggle-archive",
        label: props.isArchived ? t("messages.actions.unarchive", "Unarchive") : t("messages.actions.archive", "Archive"),
        icon: props.isArchived ? ArchiveRestore : Archive,
        onSelect: props.onToggleArchive,
        disabled: props.updatingState
      });
    }
    items.push({
      id: "delete",
      label: t("messages.actions.delete", "Delete"),
      icon: Trash2,
      onSelect: props.onDelete,
      disabled: props.updatingState
    });
    return items;
  }, [props, t]);
  return /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-2", children: [
    props.collapseToggle ? /* @__PURE__ */ jsx(
      IconButton,
      {
        type: "button",
        onClick: props.collapseToggle.onToggle,
        variant: "ghost",
        size: "sm",
        className: "mt-1 text-muted-foreground hover:text-foreground",
        "aria-label": props.collapseToggle.expanded ? t("messages.detail.hideDetails", "Hide details") : t("messages.detail.showDetails", "Show details"),
        children: props.collapseToggle.expanded ? /* @__PURE__ */ jsx(ChevronUp, { className: "h-4 w-4", "aria-hidden": true }) : /* @__PURE__ */ jsx(ChevronDown, { className: "h-4 w-4", "aria-hidden": true })
      }
    ) : null,
    /* @__PURE__ */ jsx("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ jsx(
      FormHeader,
      {
        mode: "detail",
        title: showSubject ? props.detail.subject : void 0,
        subtitle: `${t("messages.detail.from", "From")}: ${props.detail.senderName || props.detail.senderEmail || props.detail.senderUserId}`,
        statusBadge: /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: formatDateTime(props.detail.sentAt) }),
        utilityActions: canReply ? /* @__PURE__ */ jsx(
          IconButton,
          {
            type: "button",
            variant: "outline",
            size: "default",
            "aria-label": t("messages.reply", "Reply"),
            onClick: props.onReply,
            children: /* @__PURE__ */ jsx(Reply, { className: "h-4 w-4", "aria-hidden": true })
          }
        ) : void 0,
        menuTriggerMode: "icon",
        menuAriaLabel: t("ui.actions.actions", "Actions"),
        menuActions: actionItems
      }
    ) })
  ] });
}
export {
  MessageHeader
};
//# sourceMappingURL=MessageHeader.js.map
