@extends('admin.layout')
@section('heading','Episodes')
@section('content')
<div class="premium-page-head">
    <div><span class="eyebrow">EPISODE LIBRARY</span><h1>Episodes</h1><p>Browse and control all imported episodes in one premium grid.</p></div>
</div>
<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 episode or show...">
        @if(request('q'))<a href="{{ route('admin.episodes') }}"><i class="fa-solid fa-xmark"></i></a>@endif
        <button>Search</button>
    </form>
    <div class="result-count"><strong>{{ number_format($items->total()) }}</strong> episodes</div>
</div>
<div class="premium-admin-grid premium-episode-grid">
@forelse($items as $x)
@php($img=app(\App\Services\MediaStorageService::class)->url($x->still_path))
<article class="premium-content-card episode-card">
    <div class="episode-thumb">
        <img src="{{ $img ?: 'https://placehold.co/640x360?text=Episode' }}" 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?->season_number ?? 0,2,'0',STR_PAD_LEFT) }}E{{ str_pad($x->episode_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-regular fa-clock"></i> {{ $x->runtime ? $x->runtime.' min' : 'N/A' }}</span><span><i class="fa-solid fa-star"></i> {{ $x->vote_average ?: 'N/A' }}</span></div>
        <div class="premium-card-actions">
            <form method="post" action="{{ route('admin.episodes.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.episodes.destroy',$x) }}">@csrf @method('DELETE')<button class="premium-btn premium-btn-delete" onclick="return confirm('Delete this episode permanently?')"><i class="fa-solid fa-trash-can"></i></button></form>
        </div>
    </div>
</article>
@empty<div class="premium-empty"><i class="fa-solid fa-list"></i><h3>No episodes found</h3></div>@endforelse
</div>
{{ $items->links('vendor.pagination.admin-premium') }}
@endsection
