@extends('admin.layouts.app')
@section('title', 'Dashboard')
@section('page-title', 'Dashboard')

@section('content')

{{-- ── Stat Cards ── --}}
<div class="row g-3 mb-4">
    <div class="col-xl-3 col-sm-6">
        <div class="stat-card">
            <div class="stat-card-top">
                <div>
                    <div class="stat-value">{{ number_format($stats['total_users']) }}</div>
                    <div class="stat-label mt-1">Toplam Kullanıcı</div>
                </div>
                <div class="stat-icon violet"><i class="bi bi-people-fill"></i></div>
            </div>
        </div>
    </div>
    <div class="col-xl-3 col-sm-6">
        <div class="stat-card">
            <div class="stat-card-top">
                <div>
                    <div class="stat-value">{{ number_format($stats['premium_users']) }}</div>
                    <div class="stat-label mt-1">Premium Üye</div>
                </div>
                <div class="stat-icon orange"><i class="bi bi-star-fill"></i></div>
            </div>
        </div>
    </div>
    <div class="col-xl-3 col-sm-6">
        <div class="stat-card">
            <div class="stat-card-top">
                <div>
                    <div class="stat-value">{{ number_format($stats['total_animes']) }}</div>
                    <div class="stat-label mt-1">Toplam Anime</div>
                </div>
                <div class="stat-icon cyan"><i class="bi bi-play-circle-fill"></i></div>
            </div>
        </div>
    </div>
    <div class="col-xl-3 col-sm-6">
        <div class="stat-card">
            <div class="stat-card-top">
                <div>
                    <div class="stat-value">{{ number_format($stats['total_episodes']) }}</div>
                    <div class="stat-label mt-1">Toplam Bölüm</div>
                </div>
                <div class="stat-icon green"><i class="bi bi-collection-play-fill"></i></div>
            </div>
        </div>
    </div>
    <div class="col-xl-3 col-sm-6">
        <div class="stat-card">
            <div class="stat-card-top">
                <div>
                    <div class="stat-value">{{ number_format($stats['total_comments']) }}</div>
                    <div class="stat-label mt-1">Toplam Yorum</div>
                </div>
                <div class="stat-icon violet"><i class="bi bi-chat-dots-fill"></i></div>
            </div>
        </div>
    </div>
    <div class="col-xl-3 col-sm-6">
        <div class="stat-card">
            <div class="stat-card-top">
                <div>
                    <div class="stat-value">{{ number_format($stats['pending_comments']) }}</div>
                    <div class="stat-label mt-1">Bekleyen Yorum</div>
                </div>
                <div class="stat-icon red"><i class="bi bi-clock-fill"></i></div>
            </div>
            @if($stats['pending_comments'] > 0)
            <a href="{{ route('admin.comments.index', ['status'=>'pending']) }}" class="btn btn-sm btn-outline-danger mt-2 w-100">
                <i class="bi bi-arrow-right"></i> İncele
            </a>
            @endif
        </div>
    </div>
    <div class="col-xl-3 col-sm-6">
        <div class="stat-card">
            <div class="stat-card-top">
                <div>
                    <div class="stat-value">{{ number_format($stats['active_subs']) }}</div>
                    <div class="stat-label mt-1">Aktif Abonelik</div>
                </div>
                <div class="stat-icon orange"><i class="bi bi-credit-card-fill"></i></div>
            </div>
        </div>
    </div>
</div>

{{-- ── Alt Paneller ── --}}
<div class="row g-3">

    {{-- Son Kullanıcılar --}}
    <div class="col-lg-4">
        <div class="card h-100">
            <div class="card-header">
                <i class="bi bi-people" style="color:var(--accent-lt)"></i>
                <h6>Son Kayıtlar</h6>
                <a href="{{ route('admin.users.index') }}" class="btn btn-sm btn-outline-secondary ms-auto">Tümü</a>
            </div>
            <div class="card-body p-0">
                @forelse($recent_users as $user)
                <div class="d-flex align-items-center gap-3 px-4 py-3 border-bottom border-0" style="border-bottom:1px solid var(--border) !important">
                    <div class="user-avatar sm">{{ strtoupper(substr($user->name, 0, 1)) }}</div>
                    <div class="flex-grow-1 overflow-hidden">
                        <div style="font-size:13px;font-weight:600;color:var(--text)" class="text-truncate">{{ $user->name }}</div>
                        <div style="font-size:11.5px;color:var(--text2)">{{ $user->created_at->diffForHumans() }}</div>
                    </div>
                    @if($user->membership === 'premium')
                        <span class="badge badge-premium">PRO</span>
                    @else
                        <span class="badge badge-free">Ücretsiz</span>
                    @endif
                </div>
                @empty
                <div class="empty-state py-5">
                    <i class="bi bi-people"></i>
                    <p>Henüz kullanıcı yok.</p>
                </div>
                @endforelse
            </div>
        </div>
    </div>

    {{-- Son Animeler --}}
    <div class="col-lg-4">
        <div class="card h-100">
            <div class="card-header">
                <i class="bi bi-play-circle" style="color:var(--info)"></i>
                <h6>Son Animeler</h6>
                <a href="{{ route('admin.animes.index') }}" class="btn btn-sm btn-outline-secondary ms-auto">Tümü</a>
            </div>
            <div class="card-body p-0">
                @forelse($recent_animes as $anime)
                <div class="d-flex align-items-center gap-3 px-4 py-3" style="border-bottom:1px solid var(--border)">
                    @if($anime->cover_image)
                        <img src="{{ $anime->coverUrl }}" alt="" style="width:38px;height:54px;object-fit:cover;border-radius:6px;flex-shrink:0;background:var(--surface)">
                    @else
                        <div style="width:38px;height:54px;border-radius:6px;background:var(--surface);display:flex;align-items:center;justify-content:center;flex-shrink:0;color:var(--text3)"><i class="bi bi-image"></i></div>
                    @endif
                    <div class="flex-grow-1 overflow-hidden">
                        <div style="font-size:13px;font-weight:600;color:var(--text)" class="text-truncate">{{ $anime->title }}</div>
                        <div style="font-size:11.5px;color:var(--text2)">{{ $anime->created_at->diffForHumans() }}</div>
                    </div>
                    <span class="badge {{ $anime->is_published ? 'bg-success' : 'bg-secondary' }}">
                        {{ $anime->is_published ? 'Yayında' : 'Taslak' }}
                    </span>
                </div>
                @empty
                <div class="empty-state py-5">
                    <i class="bi bi-play-circle"></i>
                    <p>Henüz anime eklenmemiş.</p>
                </div>
                @endforelse
            </div>
        </div>
    </div>

    {{-- Son Yorumlar --}}
    <div class="col-lg-4">
        <div class="card h-100">
            <div class="card-header">
                <i class="bi bi-chat-dots" style="color:var(--warning)"></i>
                <h6>Son Yorumlar</h6>
                <a href="{{ route('admin.comments.index') }}" class="btn btn-sm btn-outline-secondary ms-auto">Tümü</a>
            </div>
            <div class="card-body p-0">
                @forelse($recent_comments as $comment)
                <div class="px-4 py-3" style="border-bottom:1px solid var(--border)">
                    <div class="d-flex align-items-center justify-content-between gap-2 mb-1">
                        <span style="font-size:13px;font-weight:600;color:var(--text)">{{ $comment->user?->name ?? 'Silinmiş Kullanıcı' }}</span>
                        <span class="badge {{ $comment->status === 'approved' ? 'bg-success' : ($comment->status === 'pending' ? 'bg-warning' : 'bg-danger') }}">
                            {{ match($comment->status) { 'approved'=>'Onaylı', 'pending'=>'Bekliyor', default=>'Reddedildi' } }}
                        </span>
                    </div>
                    <div style="font-size:12.5px;color:var(--text2);line-height:1.4">{{ Str::limit($comment->content, 65) }}</div>
                </div>
                @empty
                <div class="empty-state py-5">
                    <i class="bi bi-chat-dots"></i>
                    <p>Henüz yorum yok.</p>
                </div>
                @endforelse
            </div>
        </div>
    </div>
</div>

@endsection
