"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import * as React from "react";
import { Sparkles } from "lucide-react";
import { useLocale, useT } from "@open-mercato/shared/lib/i18n/context";
import { Button } from "@open-mercato/ui/primitives/button";
import { Popover, PopoverContent, PopoverTrigger } from "@open-mercato/ui/primitives/popover";
import { SimpleTooltip } from "@open-mercato/ui/primitives/tooltip";
import { formatTimeRange } from "./EventBlock.js";
const PLATFORM_FULL_LABELS = {
  zoom: { key: "customers.calendar.platformFull.zoom", fallback: "Zoom" },
  meet: { key: "customers.calendar.platformFull.meet", fallback: "Google Meet" },
  slack: { key: "customers.calendar.platformFull.slack", fallback: "Slack" },
  teams: { key: "customers.calendar.platformFull.teams", fallback: "Microsoft Teams" }
};
function EventPeekPopover({
  item,
  open,
  joinUrl,
  aiSummaries,
  canManage = true,
  onOpenChange,
  onJoin,
  onEdit,
  children
}) {
  const t = useT();
  const locale = useLocale();
  const title = item.title || t("customers.calendar.grid.untitled", "Untitled");
  const dateLabel = React.useMemo(
    () => new Intl.DateTimeFormat(locale, { weekday: "short", month: "short", day: "numeric" }).format(item.start),
    [locale, item.start]
  );
  const timeRange = item.allDay ? t("customers.calendar.grid.allDay", "All day") : formatTimeRange(locale, item.start, item.end);
  const attendeeCount = item.participants.length;
  const attendeesLabel = attendeeCount === 1 ? t("customers.calendar.peek.attendee", "1 attendee") : t("customers.calendar.peek.attendees", "{count} attendees", { count: attendeeCount });
  const platformLabel = item.locationKind === "platform" && item.platform ? t(PLATFORM_FULL_LABELS[item.platform].key, PLATFORM_FULL_LABELS[item.platform].fallback) : null;
  const metaParts = [platformLabel, attendeeCount > 0 ? attendeesLabel : null].filter(
    (part) => Boolean(part)
  );
  const showSummary = aiSummaries && metaParts.length > 0;
  const showJoin = aiSummaries && Boolean(joinUrl);
  return /* @__PURE__ */ jsxs(Popover, { open, onOpenChange, children: [
    /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children }),
    /* @__PURE__ */ jsx(PopoverContent, { align: "start", side: "right", sideOffset: 8, className: "w-56 p-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
      /* @__PURE__ */ jsx("p", { className: "text-sm font-semibold leading-5 text-foreground", children: title }),
      /* @__PURE__ */ jsx("p", { className: "text-xs leading-4 text-muted-foreground", children: `${dateLabel} \xB7 ${timeRange}` }),
      showSummary ? /* @__PURE__ */ jsxs("p", { className: "flex items-center gap-1 text-xs leading-4 text-muted-foreground", children: [
        /* @__PURE__ */ jsx(Sparkles, { "aria-hidden": true, className: "size-3.5 shrink-0" }),
        /* @__PURE__ */ jsx("span", { className: "truncate", children: metaParts.join(" \xB7 ") })
      ] }) : null,
      /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 pt-1", children: [
        showJoin ? /* @__PURE__ */ jsx(Button, { type: "button", size: "sm", onClick: () => onJoin(item), children: t("customers.calendar.peek.join", "Join") }) : null,
        canManage ? /* @__PURE__ */ jsx(
          Button,
          {
            type: "button",
            size: "sm",
            variant: "secondary",
            onClick: () => {
              onOpenChange(false);
              onEdit(item);
            },
            children: t("customers.calendar.peek.edit", "Edit")
          }
        ) : /* @__PURE__ */ jsx(
          SimpleTooltip,
          {
            content: t(
              "customers.calendar.peek.editForbidden",
              "You don't have permission to edit events"
            ),
            children: /* @__PURE__ */ jsx("span", { className: "inline-flex", children: /* @__PURE__ */ jsx(Button, { type: "button", size: "sm", variant: "secondary", disabled: true, className: "pointer-events-none", children: t("customers.calendar.peek.edit", "Edit") }) })
          }
        )
      ] })
    ] }) })
  ] });
}
export {
  EventPeekPopover
};
//# sourceMappingURL=EventPeekPopover.js.map
