@let item = selectedItem();
@if (item && item.info) {
    @let info = item.info;
    <app-content-hero
        [title]="info.name"
        [description]="info.plot"
        [posterUrl]="info.cover"
        [backdropUrl]="getBackdropUrl(info)"
        (backClicked)="goBack()"
    >
        <ng-container hero-tags>
            @if (info.releaseDate) {
                <span class="details__tag">{{
                    info.releaseDate | slice: 0 : 4
                }}</span>
            }
            @if (info.genre) {
                <span class="details__tag">{{ info.genre }}</span>
            }
            @if (info.episode_run_time) {
                <span class="details__tag"
                    >{{ info.episode_run_time }} min/ep</span
                >
            }
            @if (info.rating) {
                <span class="details__tag details__tag--rating">
                    ⭐ {{ info.rating }}
                </span>
            }
        </ng-container>

        <ng-container hero-meta>
            @if (info.cast) {
                <div class="details__meta-item">
                    <span class="label">{{ 'XTREAM.CAST' | translate }}</span>
                    <span class="value">{{ info.cast }}</span>
                </div>
            }
            @if (info.director) {
                <div class="details__meta-item">
                    <span class="label">{{
                        'XTREAM.DIRECTOR' | translate
                    }}</span>
                    <span class="value">{{ info.director }}</span>
                </div>
            }
        </ng-container>

        <ng-container hero-actions>
            @if (quickStartAction(); as action) {
                <button
                    class="play-btn"
                    data-testid="series-quick-start"
                    (click)="playQuickStartEpisode()"
                    [disabled]="action.disabled"
                >
                    <span class="play-btn__icon-shell" aria-hidden="true">
                        <mat-icon class="play-btn__icon">{{
                            action.icon
                        }}</mat-icon>
                    </span>
                    <span class="play-btn__copy">
                        <span class="play-btn__label">
                            {{ action.labelKey | translate }}
                        </span>
                        <span class="play-btn__meta">
                            {{ action.episodeLabel }}
                        </span>
                    </span>
                </button>
            }
            @if (!isFavorite()) {
                <button class="favorite-btn" (click)="toggleFavorite()">
                    <mat-icon>add</mat-icon>
                    {{ 'PORTALS.ADD_TO_FAVORITES' | translate }}
                </button>
            } @else {
                <button
                    class="favorite-btn favorite-btn--active"
                    (click)="toggleFavorite()"
                >
                    <mat-icon>check</mat-icon>
                    {{ 'PORTALS.REMOVE_FROM_FAVORITES' | translate }}
                </button>
            }
        </ng-container>

        @if (inlinePlayback(); as playback) {
            <app-portal-inline-player
                [playback]="playback"
                (timeUpdate)="handleInlineTimeUpdate($event)"
                (closed)="closeInlinePlayer()"
                (streamUrlCopied)="showCopyNotification()"
                (externalFallbackRequested)="
                    handleExternalFallbackRequest($event)
                "
            />
        }

        <app-season-container
            [seasons]="item.episodes"
            [seriesId]="item.series_id"
            [playlistId]="currentPlaylistId()"
            [seriesTitle]="info.name"
            [playbackPositions]="episodePlaybackPositions()"
            [xtreamDownloadContext]="xtreamDownloadContext()"
            [openingEpisodeId]="openingEpisodeId()"
            [activeEpisodeId]="activeEpisodeId()"
            (episodeClicked)="playEpisode($event)"
            (playbackToggleRequested)="handlePlaybackToggleRequested($event)"
        />
    </app-content-hero>
} @else if (detailsError()) {
    <app-content-hero
        [errorMessage]="detailsError() ?? undefined"
        (backClicked)="goBack()"
    />
} @else {
    <app-content-hero [isLoading]="true" (backClicked)="goBack()" />
}
