import { html } from "/js/lib/lit-html.js"; import { avatarGroupTemplate } from "/js/templates/avatarGroup.template.js"; import "/js/components/app-icon.js"; import { getDisplayName, isAvailableJoinLinkPreview } from "/js/dataHelpers.js"; import { linkToProfile } from "/js/navigation.js"; function deriveJoinLinkAction({ preview, currentConvoId }) { if (!isAvailableJoinLinkPreview(preview)) return null; const convoId = preview.convo?.id ?? null; const isFollowing = preview.owner?.viewer?.followedBy ?? false; const hasRequested = !convoId && preview.viewer?.requestedAt != null; if (convoId && convoId === currentConvoId) { return { type: "copy", label: "Copy link", icon: "link", side: "left", disabled: false, }; } if (convoId) { return { type: "open", label: "Open chat", icon: "arrow-right", side: "right", disabled: false, }; } if (preview.memberCount >= preview.memberLimit) { return { type: "full", label: "This chat is full", icon: "hand", side: "left", disabled: true, }; } if (preview.joinRule === "followedByOwner" && !isFollowing) { return { type: "follow-required", label: "Only people the chat owner follows can join", icon: "hand", side: "left", disabled: true, }; } if (hasRequested) { return { type: "requested", label: "Requested", icon: "check", side: "left", disabled: false, }; } return { type: preview.requireApproval ? "request" : "join", label: preview.requireApproval ? "Request to join" : "Join", icon: "join", side: "left", disabled: false, }; } const ACTION_ICONS = { link: () => html``, "arrow-right": () => html``, join: () => html``, check: () => html``, hand: () => html``, }; function unavailableTemplate() { return html``; } function ownerRowTemplate({ owner }) { const displayName = getDisplayName(owner); return html``; } function actionButtonTemplate({ action, preview }) { if (!action) return null; const iconFn = ACTION_ICONS[action.icon]; const icon = iconFn ? iconFn() : null; return html``; } export function chatJoinLinkEmbedTemplate({ embed, currentConvoId }) { const preview = embed?.joinLinkPreview; if (!isAvailableJoinLinkPreview(preview)) { return html``; } const action = deriveJoinLinkAction({ preview, currentConvoId }); const avatarProfiles = preview.convo?.members ?? [preview.owner]; return html``; }