"use client"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useEffect, useState } from "react"; import { conversationTitle, otherPeople, searchConversations, } from "../messenger.js"; import { IconCheck, IconPencil, IconUsers } from "./icons.js"; import { MessengerAvatar } from "./MessageAttachments.js"; import { Sheet } from "./Sheet.js"; /** How many conversations one forward may go to: a copy is a message each. */ export const FORWARD_MAX = 5; /** * Forward a message: choose conversations (the viewer's own, newest first, * searchable), then send one copy to each. Nothing is sent until Send. */ export function ForwardSheet({ message, conversations, viewerId, agents, labels, onClose, onSend, }) { const [query, setQuery] = useState(""); const [chosen, setChosen] = useState([]); useEffect(() => { setQuery(""); setChosen([]); }, [message]); const title = (c) => conversationTitle(c, viewerId, labels.titles, agents); // Every conversation the viewer can still write in, but the one it came from. const shown = searchConversations(conversations, query, title).filter((c) => c.id !== message?.threadId && c.participants.find((p) => p.actorId === viewerId)?.canWrite !== false); return (_jsx(Sheet, { open: message !== null, onClose: onClose, title: labels.forwardTitle, closeLabel: labels.close, children: _jsxs("div", { className: "ck-msgr-forward", children: [_jsx("input", { className: "ck-msgr-forward-search", type: "search", value: query, onChange: (e) => setQuery(e.target.value), placeholder: labels.forwardSearch, "aria-label": labels.forwardSearch }), _jsx("ul", { className: "ck-msgr-forward-list", children: shown.map((c) => { const people = otherPeople(c, viewerId, agents); const face = people.length === 1 ? people[0] : undefined; const on = chosen.includes(c.id); const full = !on && chosen.length >= FORWARD_MAX; return (_jsx("li", { children: _jsxs("button", { type: "button", className: "ck-msgr-forward-row", "aria-pressed": on, disabled: full, onClick: () => setChosen((now) => (on ? now.filter((id) => id !== c.id) : [...now, c.id])), children: [_jsx(MessengerAvatar, { name: face?.name ?? title(c), src: face?.avatarUrl, size: "sm", fallback: people.length > 1 ? _jsx(IconUsers, {}) : _jsx(IconPencil, {}) }), _jsx("span", { className: "ck-msgr-forward-name ck-truncate", children: title(c) }), _jsx("span", { className: "ck-msgr-forward-tick", "aria-hidden": true, children: on && _jsx(IconCheck, {}) })] }) }, c.id)); }) }), _jsx("button", { type: "button", className: "ck-msgr-btn ck-msgr-btn-primary", disabled: chosen.length === 0, onClick: () => message && onSend(message, chosen), children: labels.forwardSend.replace("{n}", String(chosen.length || "")) })] }) })); } //# sourceMappingURL=ForwardSheet.js.map