@extends('admin.layouts.app')
@section('title','Anime İstekleri')
@section('page-title','Anime İstekleri')

@section('content')

<div class="page-header">
    <div>
        <h5 style="font-size:18px;font-weight:700;color:var(--text);margin:0">Anime İstekleri</h5>
    </div>
    {{-- Durum filtreleri --}}
    <div style="display:flex;gap:6px;flex-wrap:wrap">
        @foreach(['all'=>'Tümü','pending'=>'Bekliyor','approved'=>'Onaylandı','added'=>'Eklendi','rejected'=>'Reddedildi'] as $key=>$lbl)
        <a href="{{ route('admin.anime-requests.index',['status'=>$key]) }}"
           class="btn btn-sm {{ $status===$key ? 'btn-primary' : 'btn-secondary' }}">
            {{ $lbl }}
            @if(isset($counts[$key]))
                <span class="badge {{ $status===$key ? 'bg-light text-dark' : 'bg-secondary' }} ms-1">{{ $counts[$key] }}</span>
            @endif
        </a>
        @endforeach
    </div>
</div>

<div class="table-wrap">
    <div class="table-responsive">
        <table class="table">
            <thead>
                <tr>
                    <th style="padding-left:20px">Anime</th>
                    <th>İsteyen</th>
                    <th style="text-align:center">Oy</th>
                    <th style="text-align:center">Durum</th>
                    <th>Tarih</th>
                    <th style="text-align:right;padding-right:20px">İşlem</th>
                </tr>
            </thead>
            <tbody>
                @forelse($requests as $req)
                @php $s = \App\Models\AnimeRequest::STATUSES[$req->status] ?? ['label'=>$req->status,'color'=>'#8b87a8']; @endphp
                <tr>
                    <td style="padding-left:20px">
                        <div style="font-size:13.5px;font-weight:700;color:var(--text)">{{ $req->title }}</div>
                        @if($req->original_title)
                            <div style="font-size:12px;color:var(--text2)">{{ $req->original_title }}</div>
                        @endif
                        @if($req->note)
                            <div style="font-size:12px;color:var(--text3);margin-top:3px;font-style:italic">
                                <i class="bi bi-chat-right-text" style="font-size:10px;margin-right:3px"></i>{{ Str::limit($req->note,70) }}
                            </div>
                        @endif
                        @if($req->admin_note)
                            <div style="font-size:12px;color:var(--warning);margin-top:2px">
                                <i class="bi bi-shield" style="font-size:10px;margin-right:3px"></i>{{ $req->admin_note }}
                            </div>
                        @endif
                    </td>
                    <td>
                        @if($req->user)
                            <div style="font-size:13px;font-weight:600;color:var(--text)">{{ $req->user->name }}</div>
                            <div style="font-size:11.5px;color:var(--text2)">{{ $req->user->email }}</div>
                        @else
                            <span style="color:var(--text3)">Silinmiş</span>
                        @endif
                    </td>
                    <td style="text-align:center">
                        <span class="badge" style="background:var(--accent-dim);color:var(--accent-lt);font-size:12px;padding:4px 10px">
                            <i class="bi bi-heart-fill" style="font-size:10px;margin-right:3px"></i>{{ $req->vote_count }}
                        </span>
                    </td>
                    <td style="text-align:center">
                        <span class="badge" style="background:{{ $s['color'] }}22;color:{{ $s['color'] }};border:1px solid {{ $s['color'] }}44">
                            {{ $s['label'] }}
                        </span>
                    </td>
                    <td style="font-size:12.5px;color:var(--text2)">{{ $req->created_at->format('d.m.Y') }}</td>
                    <td style="text-align:right;padding-right:20px">
                        <div class="d-flex gap-1 justify-content-end flex-wrap">
                            @foreach(['approved'=>['Onayla','success'],'added'=>['Eklendi','info'],'rejected'=>['Reddet','danger']] as $st=>[$lbl,$clr])
                            @if($req->status !== $st)
                            <form method="POST" action="{{ route('admin.anime-requests.update',$req) }}">
                                @csrf @method('PATCH')
                                <input type="hidden" name="status" value="{{ $st }}">
                                <button type="submit" class="btn btn-sm btn-outline-{{ $clr }}">{{ $lbl }}</button>
                            </form>
                            @endif
                            @endforeach
                            <form method="POST" action="{{ route('admin.anime-requests.destroy',$req) }}"
                                  onsubmit="return confirm('Bu istek silinsin mi?')">
                                @csrf @method('DELETE')
                                <button type="submit" class="btn btn-sm btn-outline-danger">
                                    <i class="bi bi-trash3"></i>
                                </button>
                            </form>
                        </div>
                    </td>
                </tr>
                @empty
                <tr>
                    <td colspan="6">
                        <div class="empty-state">
                            <i class="bi bi-plus-square"></i>
                            <h6>Bu kategoride istek yok</h6>
                        </div>
                    </td>
                </tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>

<div class="mt-3">
    {{ $requests->withQueryString()->links('admin.partials.pagination') }}
</div>

@endsection
