@namespace DeepDrftPublic.Client.Controls

@* Invariant trio shared by every medium's detail page: a back link, a masthead (title + artist),
   a play/share affordance row wired to the streaming player, and slots for the medium-specific
   hero visual and metadata block. The Cut/Session/Mix detail pages all compose this;
   per-medium variance rides the Hero and MetaContent render fragments. *@

@* Ambient environment layer (Phase 12 §3c/§3f mode B): an optional full-bleed layer rendered BEHIND
   the scaffold content. The visualizer mounted here positions itself fixed/inset:0 (its own CSS), so
   this slot's only job is to render it before the content and put the content into a foreground
   stacking context above it. Absent slot = no ambient layer and no foreground promotion → today's
   plain background, byte-for-byte (Liskov). *@
@if (Ambient is not null)
{
    @Ambient
}

<div class="deepdrft-track-detail-container @(Ambient is not null ? "deepdrft-track-detail-foreground" : null)">

    @* Two-end top row: back link (left) | optional action (right), on one SpaceBetween row. The action
       slot stays null for media that don't supply it (Track/Cut/Session), so SpaceBetween collapses to
       the back link alone at the left edge. The Mix detail page fills the action with its lava-lamp
       toggle and renders its knob band below via TopContent. *@
    <div class="deepdrft-track-detail-top-row">
        <MudStack Row AlignItems="AlignItems.Center" Justify="Justify.SpaceBetween">
            <MudLink Href="@BackHref" Typo="Typo.body2" Class="deepdrft-track-detail-back">
                &larr; @BackLabel
            </MudLink>
            
            @TopContent
            
            @TopRightAction
        </MudStack>
    </div>

    @* The header region. A composer that wants the default masthead+play row supplies nothing; one
       that needs a different arrangement (e.g. the Cut album's left-meta / right-cover split) supplies
       its own Header fragment. Layout variance rides this slot, never a boolean flag (Phase 9 §5.3).
       ShowHeader (a gate, not a layout flag) suppresses the region entirely for composers that carry
       title/artist/play elsewhere — Mix overlays them on its hero. *@
    @if (ShowHeader)
    {
        @if (Header is not null)
        {
            @Header
        }
        else
        {
            <MudStack Row AlignItems="AlignItems.Start" Justify="Justify.SpaceBetween" Style="margin: 2rem 0 1.5rem;">
                <div class="deepdrft-track-detail-masthead">
                    <MudText Typo="Typo.h3">@Title</MudText>
                    <MudText Typo="Typo.h6" Color="Color.Primary">@Artist</MudText>
                </div>

                @* Play only makes sense once a playable track is resolved. *@
                @if (Track is not null)
                {
                    <MudStack Row AlignItems="AlignItems.Center" Spacing="1">
                        <PlayStateIcon Track="@Track" Size="Size.Large" Color="Color.Secondary" OnToggle="@PlayTrack" />
                    </MudStack>
                }
            </MudStack>
        }
    }

    @Hero

    @if (MetaContent is not null && ShowMeta)
    {
        <MudDivider />
        <div class="deepdrft-track-detail-meta">
            @MetaContent
        </div>
    }

    @* Multi-track body region (the Cut album's track list). Single-track media leave it null. *@
    @BodyContent

    @* The default share row is bound to the single resolved track. A composer that owns its own share
       affordance (the Cut header carries Play + Share inline) suppresses it via ShowShareRow. *@
    @if (Track is not null && ShowShareRow)
    {
        <div class="deepdrft-share-row">
            <SharePopover EntryKey="@Track.EntryKey" />
        </div>
    }

</div>
