"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import * as React from "react";
import { Inbox, ExternalLink, Calendar } from "lucide-react";
import { useRouter } from "next/navigation";
import { Button } from "@open-mercato/ui/primitives/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 ProposalCreatedRenderer({
  notification,
  onAction,
  onDismiss,
  actions = []
}) {
  const t = useT();
  const router = useRouter();
  const [executing, setExecuting] = React.useState(false);
  const isUnread = notification.status === "unread";
  const actionCount = notification.bodyVariables?.actionCount;
  const reviewAction = actions.find((action) => action.id === "review") ?? actions[0] ?? null;
  const handleReview = async () => {
    if (!reviewAction) {
      if (notification.linkHref) router.push(notification.linkHref);
      return;
    }
    setExecuting(true);
    try {
      await onAction(reviewAction.id);
    } finally {
      setExecuting(false);
    }
  };
  return /* @__PURE__ */ jsxs(
    "div",
    {
      className: cn(
        "group relative px-4 py-3 hover:bg-muted/50 cursor-pointer transition-colors border-l-4 border-l-status-warning-border",
        isUnread && "bg-status-warning-bg"
      ),
      onClick: handleReview,
      onKeyDown: (e) => {
        if (e.key === "Enter" || e.key === " ") {
          e.preventDefault();
          handleReview();
        }
      },
      role: "button",
      tabIndex: 0,
      children: [
        isUnread && /* @__PURE__ */ jsx("div", { className: "absolute left-1.5 top-1/2 -translate-y-1/2 h-2 w-2 rounded-full bg-primary" }),
        /* @__PURE__ */ jsxs("div", { className: "flex gap-3", children: [
          /* @__PURE__ */ jsx("div", { className: "flex-shrink-0 mt-0.5", children: /* @__PURE__ */ jsx("div", { className: "h-10 w-10 rounded-lg bg-status-warning-bg flex items-center justify-center", children: /* @__PURE__ */ jsx(Inbox, { className: "h-5 w-5 text-status-warning-icon" }) }) }),
          /* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0", children: [
            /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-2", children: [
              /* @__PURE__ */ jsx("h4", { className: cn("text-sm font-medium", isUnread && "font-semibold"), children: notification.title }),
              /* @__PURE__ */ jsxs("span", { className: "flex-shrink-0 text-xs text-muted-foreground flex items-center gap-1", children: [
                /* @__PURE__ */ jsx(Calendar, { className: "h-3 w-3" }),
                formatRelativeTime(notification.createdAt, { translate: t }) ?? ""
              ] })
            ] }),
            actionCount && /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: t("inbox_ops.notifications.renderer.actionCount", "{count} proposed actions", { count: actionCount }) }),
            /* @__PURE__ */ jsxs("div", { className: "mt-3 flex gap-2", children: [
              /* @__PURE__ */ jsxs(
                Button,
                {
                  variant: "default",
                  size: "sm",
                  onClick: (event) => {
                    event.stopPropagation();
                    handleReview();
                  },
                  disabled: executing || !reviewAction && !notification.linkHref,
                  className: "gap-1",
                  children: [
                    /* @__PURE__ */ jsx(ExternalLink, { className: "h-3 w-3" }),
                    t("inbox_ops.action.review", "Review")
                  ]
                }
              ),
              /* @__PURE__ */ jsx(
                Button,
                {
                  variant: "ghost",
                  size: "sm",
                  onClick: (event) => {
                    event.stopPropagation();
                    onDismiss();
                  },
                  children: t("notifications.actions.dismiss", "Dismiss")
                }
              )
            ] })
          ] })
        ] })
      ]
    }
  );
}
var ProposalCreatedRenderer_default = ProposalCreatedRenderer;
export {
  ProposalCreatedRenderer,
  ProposalCreatedRenderer_default as default
};
//# sourceMappingURL=ProposalCreatedRenderer.js.map
