/** 組出可 iframe 嵌入的播放器 URL（對外使用公開房間 id） */
export function buildEmbedUrl(origin: string, publicRoomId: string): string {
    const base = String(origin ?? '').trim().replace(/\/$/, '')
    const id = String(publicRoomId ?? '').trim()
    if (!base || !id) return ''
    return `${base}/embed/stream/${encodeURIComponent(id)}`
}

/** 產生與 YouTube / Twitch 類似的 iframe HTML */
export function buildEmbedIframeHtml(
    embedUrl: string,
    options?: { width?: number; height?: number; title?: string }
): string {
    const url = String(embedUrl ?? '').trim()
    if (!url) return ''
    const width = options?.width ?? 560
    const height = options?.height ?? 315
    const title = String(options?.title ?? 'NoiR Live').replace(/"/g, '&quot;')
    return `<iframe src="${url}" width="${width}" height="${height}" frameborder="0" allowfullscreen allow="autoplay; fullscreen; picture-in-picture" title="${title}"></iframe>`
}
