@extends('admin.layouts.app')
@section('title', 'Kullanıcılar')
@section('page-title', 'Kullanıcılar')

@section('content')

<div class="page-header">
    <div>
        <h5 style="font-size:18px;font-weight:700;color:var(--text);margin:0">
            Kullanıcılar
            <span style="font-size:13px;font-weight:600;color:var(--text2);margin-left:6px">{{ number_format($users->total()) }} toplam</span>
        </h5>
    </div>
</div>

{{-- ── Filters ── --}}
<div class="filter-card mb-3">
    <form method="GET" class="d-flex flex-wrap gap-2 align-items-end">
        <div class="search-input-wrap flex-grow-1" style="min-width:180px;max-width:300px">
            <i class="bi bi-search"></i>
            <input type="text" name="search" class="form-control" placeholder="İsim veya e-posta..." value="{{ request('search') }}">
        </div>
        <select name="membership" class="form-select" style="width:auto;min-width:130px">
            <option value="">Tüm Üyelik</option>
            <option value="free"    {{ request('membership')=='free'    ?'selected':'' }}>Ücretsiz</option>
            <option value="premium" {{ request('membership')=='premium' ?'selected':'' }}>Premium</option>
        </select>
        <select name="role" class="form-select" style="width:auto;min-width:130px">
            <option value="">Tüm Roller</option>
            <option value="user"      {{ request('role')=='user'      ?'selected':'' }}>Kullanıcı</option>
            <option value="moderator" {{ request('role')=='moderator' ?'selected':'' }}>Moderatör</option>
            <option value="admin"     {{ request('role')=='admin'     ?'selected':'' }}>Admin</option>
        </select>
        <div class="d-flex gap-2">
            <button type="submit" class="btn btn-primary btn-sm"><i class="bi bi-funnel"></i> Filtrele</button>
            <a href="{{ route('admin.users.index') }}" class="btn btn-secondary btn-sm"><i class="bi bi-x-lg"></i></a>
        </div>
    </form>
</div>

{{-- ── Table ── --}}
<div class="table-wrap">
    <div class="table-responsive">
        <table class="table">
            <thead>
                <tr>
                    <th style="padding-left:20px">Kullanıcı</th>
                    <th>Rol</th>
                    <th>Üyelik</th>
                    <th>Premium Bitiş</th>
                    <th style="text-align:center">Durum</th>
                    <th>Kayıt Tarihi</th>
                    <th style="text-align:right;padding-right:20px">İşlem</th>
                </tr>
            </thead>
            <tbody>
                @forelse($users as $user)
                <tr>
                    <td style="padding-left:20px">
                        <div class="d-flex align-items-center gap-3">
                            <div class="user-avatar sm">
                                @if($user->avatar)
                                    <img src="{{ \App\Support\MediaUrl::fromStoragePath($user->avatar) }}" alt="">
                                @else
                                    {{ strtoupper(substr($user->name, 0, 1)) }}
                                @endif
                            </div>
                            <div class="overflow-hidden">
                                <div style="font-size:13.5px;font-weight:600;color:var(--text)">{{ $user->name }}</div>
                                <div style="font-size:12px;color:var(--text2)">{{ $user->email }}</div>
                            </div>
                        </div>
                    </td>
                    <td>
                        @if($user->role === 'admin')
                            <span class="badge bg-danger">Admin</span>
                        @elseif($user->role === 'moderator')
                            <span class="badge bg-info" style="color:#000">Moderatör</span>
                        @else
                            <span class="badge bg-secondary">Kullanıcı</span>
                        @endif
                    </td>
                    <td>
                        @if($user->membership === 'premium')
                            <span class="badge badge-premium"><i class="bi bi-star-fill" style="font-size:9px;margin-right:3px"></i>Premium</span>
                        @else
                            <span class="badge badge-free">Ücretsiz</span>
                        @endif
                    </td>
                    <td style="font-size:13px;color:var(--text2)">
                        {{ $user->premium_expires_at ? $user->premium_expires_at->format('d.m.Y') : '—' }}
                    </td>
                    <td style="text-align:center">
                        @if($user->is_banned)
                            <span style="display:inline-flex;align-items:center;gap:4px;font-size:12px;font-weight:700;color:var(--danger)">
                                <i class="bi bi-slash-circle-fill" style="font-size:11px"></i> Banlı
                            </span>
                        @else
                            <span style="display:inline-flex;align-items:center;gap:4px;font-size:12px;font-weight:600;color:var(--success)">
                                <i class="bi bi-circle-fill" style="font-size:7px"></i> Aktif
                            </span>
                        @endif
                    </td>
                    <td style="font-size:13px;color:var(--text2)">
                        {{ $user->created_at->format('d.m.Y') }}
                    </td>
                    <td style="text-align:right;padding-right:20px">
                        <a href="{{ route('admin.users.show', $user) }}" class="btn btn-sm btn-secondary">
                            <i class="bi bi-eye"></i>
                            <span class="d-none d-md-inline btn-text"> Görüntüle</span>
                        </a>
                    </td>
                </tr>
                @empty
                <tr>
                    <td colspan="7">
                        <div class="empty-state">
                            <i class="bi bi-people"></i>
                            <h6>Kullanıcı bulunamadı</h6>
                            <p>Arama kriterlerinizi değiştirin.</p>
                        </div>
                    </td>
                </tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>

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

@endsection
