@extends(get_theme().'.layouts')

@php
    $this_episode = isset($episode_info) ? $episode_info->episode_number : false;
    $season = $season ?? $tv->number_of_seasons;
@endphp

@section('content')
    <div class="text-center">
        <img class="img-fluid mb-4" src="{{ img_backdrop($backdrop) }}" alt="{{ $tv->name }} {{ to_year($air_date) }}">
        <div class="row mb-3">
            <div class="col d-flex justify-content-center">
                <a href="{{ mopie_route('loading', ['id' => $tv->id ,'title' => $tv->original_name, 'action' => 'play']) }}" class="btn btn-success mx-1">{{ __('utilities.watch_now') }}</a>
                <a href="{{ mopie_route('loading', ['id' => $tv->id ,'title' => $tv->original_name, 'action' => 'register']) }}" class="btn btn-danger mx-1">{{ __('utilities.download') }}</a>
            </div>
        </div>
    </div>

    {{-- Details --}}
    <div class="card mb-3">
        <div class="card-body">
            <div class="row">
                <div class="col-md-2 col-sm-4 col-3">
                    <img class="img-fluid" src="{{ img_poster($tv->poster_path) }}" alt="Poster {{ $title }} {{ to_year($air_date) }}" title="Poster {{ $title }} {{ to_year($air_date) }}">
                </div>
                <div class="col-md-10 col-sm-8 col-9">
                    <div class="entry-title d-flex flex-column-reverse flex-md-row justify-content-between">
                        <h1 class="h2">{{ $title }} <span class="tiny text-muted">{{ to_year($air_date) }}</span></h1>
                    </div>
                    <div class="entry-info mb-3">
                        <div class="__rate">
                            @for ($i = 0; $i < 10; $i++)
                                @if ($i < round($tv->vote_average))
                                    <i class="fa fa-star text-warning"></i>
                                @else
                                    <i class="fa fa-star-o text-muted"></i>
                                @endif
                            @endfor
                        </div>
                        <div class="__info">
                            <span class="text-muted small">{{ $tv->vote_average }}/10</span> <span class="text-muted small">{{ __('utilities.by') }} {{ $tv->vote_count }} {{ __('utilities.users') }}</span>
                        </div>
                    </div>
                    <div class="entry-desciption text-muted">
                        <p>{{ $overview }}</p>
                    </div>
                    <div class="entry-table">
                        <ul class="list-unstyled">
                            <li>{{ __('utilities.released') }}: <span>{{ $air_date }}</span></li>
                            <li>{{ __('utilities.runtime') }}: <span>{{ $tv->episode_run_time[0] }} {{ __('utilities.minutes') }}</span></li>
                            <li>{{ __('utilities.genre') }}: <span>{{ collect($tv->genres)->implode('name', ', ') }}</span></li>
                            <li>{{ __('utilities.stars') }}: <span>{!! star_comma($tv->credits->cast, 5) !!}</span></li>
                            <li>{{ __('utilities.director') }}: <span>{!! director_comma($tv->credits->crew, 5) !!}</span></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

    {{-- Episode Seasson --}}
    <section class="mb-3">
        <div class="episodes">
            <div>
                <ul class="nav nav-tabs" id="episodesTab" role="tablist" style="height: auto">
                    @foreach (collect($tv->seasons)->sortKeysDesc()->all() as $item)
                        <li class="nav-item">
                            <a href="{{ mopie_route('tv.single.season', ['id' => $tv->id, 'season' => $item->season_number, 'slug' => str_slug($tv->original_name)]) }}" class="nav-link {{ $item->season_number == $season ? 'active' : '' }}" id="season-{{ $item->season_number }}-tab">
                                {{ __('utilities.season') }} {{ $item->season_number }}
                            </a>
                        </li>
                    @endforeach
                </ul>
            </div>
        </div>
        <div class="tab-content episodes_list" id="episodesTabContent">
            <div class="tab-pane fade show active" id="season-{{ $tv->number_of_seasons }}" role="tabpanel" aria-labelledby="season-{{ $tv->number_of_seasons }}-tab">
                <div class="row mt-3">
                    @foreach ($season_select as $item)
                        <div class="col-md-4 mb-3">
                            @if ($item->episode_number == $this_episode)
                                <div class="card bg-light">
                            @else
                                <div class="card">
                            @endif
                                <div class="card-body">
                                    <h5 class="card-title h6">
                                        <a href="{{ mopie_route('tv.single.season.episode', ['id'=>$tv->id, 'season' => $season, 'episode'=>$item->episode_number, 'slug' => str_slug($tv->original_name.' '.$item->name) ]) }}" class="stretched-link">{{$item->episode_number }}. {{ $item->name }}</a>
                                    </h5>
                                </div>
                            </div>
                        </div>
                    @endforeach
                </div>
            </div>
        </div>
    </section>

    {{-- TV Similars --}}
    @isset($tv->similar)
        <div class="card mb-3">
            <div class="card-header">
                <h5 class="card-title m-0">{{ __('section.title.similar') }}</h5>
            </div>
            <div class="card-body">
                <div class="row">
                    @foreach (block_id_lists($tv->similar->results) as $item)
                        <div class="col-md-3 mb-3">
                            <div class="media position-relative">
                                <img class="mr-3" width="50" src="{{ img_poster($item->poster_path) }}" alt="Image {{ $item->name }}" title="Image {{ $item->name }} ({{ to_year($item->first_air_date ?? '') }})">
                                <div class="media-body">
                                    <a href="{{ mopie_route('tv.single',['id' => $item->id, 'slug' => str_slug($item->original_name)]) }}" rel="bookmark" title="{{ $item->name }} ({{ to_year($item->first_air_date ?? '') }})" class="stretched-link">
                                        <h2 class="card-title h6 m-1">{{ $item->name }}</h2>
                                    </a>
                                    <p class="small text-secondary">{{ $item->first_air_date }}</p>
                                </div>
                            </div>
                        </div>
                    @endforeach
                </div>
            </div>
        </div>
    @endisset

    {{-- TV Recommendations --}}
    @isset($tv->recommendations)
        <div class="card mb-3">
            <div class="card-header">
                <h5 class="card-title m-0">{{ __('section.title.recommendation') }}</h5>
            </div>
            <div class="card-body">
                <div class="row">
                    @foreach (block_id_lists($tv->recommendations->results) as $item)
                        <div class="col-md-3 mb-3">
                            <div class="media position-relative">
                                <img class="mr-3" width="50" src="{{ img_poster($item->poster_path) }}" alt="Image {{ $item->name }}" title="Image {{ $item->name }} ({{ to_year($item->first_air_date ?? '') }})">
                                <div class="media-body">
                                    <a href="{{ mopie_route('tv.single',['id' => $item->id, 'slug' => str_slug($item->original_name)]) }}" rel="bookmark" title="{{ $item->name }} ({{ to_year($item->first_air_date ?? '') }})" class="stretched-link">
                                        <h2 class="card-title h6 m-1">{{ $item->name }}</h2>
                                    </a>
                                    <p class="small text-secondary">{{ $item->first_air_date }}</p>
                                </div>
                            </div>
                        </div>
                    @endforeach
                </div>
            </div>
        </div>
    @endisset

@endsection