namespace DeepDrftPublic.Client.Helpers;
///
/// Builds the iframe embed snippet the share popover copies. Two targets: a single track
/// ( → FramePlayer?TrackEntryKey=...) and a whole release
/// ( → FramePlayer?ReleaseEntryKey=...).
///
///
/// The two snippets diverge in height by design (Phase 17 §4.1, OQ6): a single-track embed has no
/// queue, so stays at the compact player height; a release embed renders the
/// always-shown queue panel below the controls, so is taller to show it
/// without clipping. Other iframe chrome (width, border radius, autoplay permission) is identical and
/// defined once in .
///
///
///
/// OQ1 Option A — collapse/expand resize handshake. The release snippet carries a tiny host-side
/// listener: the embedded player posts its desired height when the viewer collapses/expands the
/// queue panel, and the listener sizes this specific iframe to match. It is scoped to the snippet's
/// own iframe (matched by id) and ignores any message whose shape does not match, so it cannot be
/// driven by foreign frames. It degrades to Option B's behaviour if the host strips the script: the
/// panel still renders and toggles inside the iframe at its default (expanded) height — only the
/// outer resize is lost. The track snippet needs no script (no panel, no toggle).
///
///
/// Pure string composition so the snippet shape is unit-testable without rendering the component.
///
public static class EmbedSnippetBuilder
{
// Compact single-track height (the historical embed height — must not change: UC6/AC6).
private const int TrackHeight = 196;
// Release height: the compact player plus the queue panel (fixed, internally scrollable past N
// rows per OQ6). The panel collapses to the track height via the resize handshake below.
private const int ReleaseHeight = 384;
// baseUri carries a trailing slash (NavigationManager.BaseUri), so "FramePlayer" appends cleanly.
public static string ForTrack(string baseUri, string trackEntryKey)
=> Frame($"{baseUri}FramePlayer?TrackEntryKey={trackEntryKey}", TrackHeight);
public static string ForRelease(string baseUri, string releaseEntryKey)
=> Frame($"{baseUri}FramePlayer?ReleaseEntryKey={releaseEntryKey}", ReleaseHeight, ResizeScript);
private static string Frame(string src, int height, string trailingScript = "")
=> $"""{trailingScript}""";
// Host-side listener: resize #deepdrft-embed when the embedded player posts its panel height. The
// shape/origin-agnostic guard (ignores non-matching messages) keeps a foreign frame from driving
// it; the height is clamped to a sane floor so a bad payload can't collapse the player away.
private const string ResizeScript =
"""""";
}