"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import * as React from "react";
import { Share2, ExternalLink, X } from "lucide-react";
import { useRouter } from "next/navigation";
import { Button } from "@open-mercato/ui/primitives/button";
import { IconButton } from "@open-mercato/ui/primitives/icon-button";
import { cn } from "@open-mercato/shared/lib/utils";
import { formatRelativeTime } from "@open-mercato/shared/lib/time";
import { useT } from "@open-mercato/shared/lib/i18n/context";
function ConversationSharedRenderer({
  notification,
  onAction,
  onDismiss,
  actions = []
}) {
  const t = useT();
  const router = useRouter();
  const [executing, setExecuting] = React.useState(false);
  const isUnread = notification.status === "unread";
  const viewAction = actions.find((a) => a.id === "view") ?? actions[0] ?? null;
  const handleView = async () => {
    setExecuting(true);
    try {
      if (viewAction) {
        await onAction(viewAction.id);
      }
      if (notification.linkHref) router.push(notification.linkHref);
    } finally {
      setExecuting(false);
    }
  };
  const timeAgo = formatRelativeTime(notification.createdAt, { translate: t }) ?? "";
  return /* @__PURE__ */ jsxs(
    "div",
    {
      className: cn(
        "group relative flex gap-4 items-start rounded-xl p-3 transition-colors hover:bg-muted/40 cursor-pointer",
        isUnread && "bg-muted/20"
      ),
      onClick: executing ? void 0 : handleView,
      onKeyDown: (e) => {
        if (executing) return;
        if (e.key === "Enter" || e.key === " ") {
          e.preventDefault();
          handleView();
        }
      },
      role: "button",
      tabIndex: 0,
      children: [
        /* @__PURE__ */ jsxs("div", { className: "relative shrink-0 flex size-10 items-center justify-center rounded-full bg-status-info-bg", children: [
          /* @__PURE__ */ jsx(Share2, { className: "size-5 text-status-info-icon", "aria-hidden": "true" }),
          isUnread ? /* @__PURE__ */ jsx(
            "span",
            {
              className: "absolute -right-1 -top-1 size-3 rounded-full bg-accent-indigo ring-2 ring-background",
              "aria-hidden": "true"
            }
          ) : null
        ] }),
        /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [
          /* @__PURE__ */ jsx("p", { className: "truncate text-sm font-medium leading-5 tracking-tight text-foreground", children: notification.title }),
          /* @__PURE__ */ jsx("div", { className: "text-xs leading-4 text-muted-foreground", children: timeAgo ? /* @__PURE__ */ jsx("span", { className: "whitespace-nowrap", children: timeAgo }) : null }),
          /* @__PURE__ */ jsxs("div", { className: "mt-2 flex items-center gap-2", children: [
            /* @__PURE__ */ jsxs(
              Button,
              {
                type: "button",
                size: "sm",
                className: "h-8 rounded-md px-2.5 bg-accent-indigo text-accent-indigo-foreground hover:bg-accent-indigo/90",
                onClick: (e) => {
                  e.stopPropagation();
                  handleView();
                },
                disabled: executing || !viewAction && !notification.linkHref,
                children: [
                  /* @__PURE__ */ jsx(ExternalLink, { className: "size-3.5", "aria-hidden": "true" }),
                  t("ai_assistant.notifications.conversation_shared.view_button", "View Conversation")
                ]
              }
            ),
            /* @__PURE__ */ jsx(
              Button,
              {
                type: "button",
                variant: "outline",
                size: "sm",
                className: "h-8 rounded-md px-2.5",
                onClick: (e) => {
                  e.stopPropagation();
                  onDismiss();
                },
                children: t("notifications.actions.dismiss", "Dismiss")
              }
            )
          ] })
        ] }),
        /* @__PURE__ */ jsx(
          IconButton,
          {
            type: "button",
            variant: "ghost",
            size: "xs",
            className: "absolute right-2 top-2 opacity-0 transition-opacity group-hover:opacity-100 focus-visible:opacity-100",
            onClick: (e) => {
              e.stopPropagation();
              onDismiss();
            },
            "aria-label": t("notifications.actions.dismiss", "Dismiss"),
            children: /* @__PURE__ */ jsx(X, { className: "size-3.5" })
          }
        )
      ]
    }
  );
}
var ConversationSharedRenderer_default = ConversationSharedRenderer;
export {
  ConversationSharedRenderer,
  ConversationSharedRenderer_default as default
};
//# sourceMappingURL=ConversationSharedRenderer.js.map
