@extends('admin.layout')
@section('heading','Seasons')
@section('content')
<div class="premium-page-head">
    <div><span class="eyebrow">SERIES MANAGEMENT</span><h1>Seasons</h1><p>Import and manage every season with its episodes and artwork.</p></div>
</div>

<form class="premium-import-bar" method="post" action="{{ route('admin.seasons.import') }}">
    @csrf
    <select name="show_id" required><option value="">Select TV show</option>@foreach($shows as $s)<option value="{{ $s->id }}">{{ $s->title }}</option>@endforeach</select>
    <input type="number" min="0" name="season_number" placeholder="Season number" required>
    <button class="premium-btn premium-btn-primary"><i class="fa-solid fa-cloud-arrow-down"></i> Import season + episodes</button>
</form>

<div class="premium-toolbar">
    <form method="get" class="premium-search">
        <i class="fa-solid fa-magnifying-glass"></i><input name="q" value="{{ request('q') }}" placeholder="Search season or show...">
        @if(request('q'))<a href="{{ route('admin.seasons') }}"><i class="fa-solid fa-xmark"></i></a>@endif
        <button>Search</button>
    </form>
    <div class="result-count"><strong>{{ number_format($items->total()) }}</strong> seasons</div>
</div>

<div class="premium-admin-grid">
@forelse($items as $x)
@php($img=app(\App\Services\MediaStorageService::class)->url($x->poster_path))
<article class="premium-content-card">
    <div class="premium-poster">
        <img src="{{ $img ?: 'https://placehold.co/500x750?text=Season' }}" alt="{{ $x->title }}">
        <div class="poster-shade"></div>
        <span class="status-pill {{ $x->is_active ? 'is-live' : 'is-off' }}">{{ $x->is_active ? 'Published' : 'Draft' }}</span>
        <span class="type-pill">S{{ str_pad($x->season_number, 2, '0', STR_PAD_LEFT) }}</span>
    </div>
    <div class="premium-card-body">
        <h3 title="{{ $x->title }}">{{ $x->title }}</h3>
        <p class="show-name"><i class="fa-solid fa-tv"></i> {{ $x->show?->title ?: 'Unknown Show' }}</p>
        <div class="meta-row"><span><i class="fa-solid fa-list-ol"></i> {{ $x->episodes_count }} episodes</span><span><i class="fa-regular fa-calendar"></i> {{ optional($x->air_date)->format('Y') ?: 'TBA' }}</span></div>
        <div class="premium-card-actions">
            <form method="post" action="{{ route('admin.seasons.toggle',$x) }}">@csrf<button class="premium-btn {{ $x->is_active ? 'premium-btn-live' : 'premium-btn-muted' }}"><i class="fa-solid {{ $x->is_active ? 'fa-toggle-on' : 'fa-toggle-off' }}"></i> {{ $x->is_active ? 'ON' : 'OFF' }}</button></form>
            <form method="post" action="{{ route('admin.seasons.destroy',$x) }}">@csrf @method('DELETE')<button class="premium-btn premium-btn-delete" onclick="return confirm('Delete this season and its episodes?')"><i class="fa-solid fa-trash-can"></i></button></form>
        </div>
    </div>
</article>
@empty<div class="premium-empty"><i class="fa-solid fa-layer-group"></i><h3>No seasons found</h3></div>@endforelse
</div>
{{ $items->links('vendor.pagination.admin-premium') }}
@endsection
