"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import { cn } from "@open-mercato/shared/lib/utils";
function formatSentTime(value) {
  if (!value || Number.isNaN(value.getTime())) return "\u2014";
  const now = /* @__PURE__ */ new Date();
  if (now.toDateString() === value.toDateString()) {
    return value.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
  }
  return value.toLocaleDateString([], { month: "short", day: "numeric" });
}
function normalizeBody(value) {
  const normalized = (value ?? "").trim().replace(/\s+/g, " ");
  return normalized || "\u2014";
}
function MessageListComponent({ message, onClick }) {
  const t = useT();
  const senderLabel = message.senderName || "\u2014";
  const body = normalizeBody(message.body);
  const sentAtLabel = formatSentTime(message.sentAt);
  return /* @__PURE__ */ jsx(
    "div",
    {
      className: cn(
        "group min-w-0 w-full cursor-pointer rounded-md px-2 py-2 transition-colors hover:bg-muted/50",
        "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
      ),
      role: "button",
      tabIndex: 0,
      "aria-label": t("messages.openMessageA11y", "Open message from {sender}", { sender: senderLabel }),
      onClick,
      onKeyDown: (event) => {
        if (event.key === "Enter" || event.key === " ") {
          event.preventDefault();
          onClick();
        }
      },
      children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
        /* @__PURE__ */ jsx("span", { className: cn("w-40 flex-shrink-0 truncate text-sm md:w-56", message.unread ? "font-semibold" : "font-normal"), children: senderLabel }),
        /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate text-sm text-muted-foreground", children: body }),
        /* @__PURE__ */ jsx(
          "span",
          {
            className: cn("flex-shrink-0 text-xs", message.unread ? "font-semibold text-foreground" : "font-normal text-muted-foreground"),
            children: sentAtLabel
          }
        )
      ] })
    }
  );
}
var MessageListComponent_default = MessageListComponent;
export {
  MessageListComponent,
  MessageListComponent_default as default
};
//# sourceMappingURL=MessageListComponent.js.map
