@extends('layouts.app')

@section('title', 'Admin Panel - Social Scheduler')

@section('content')
<div class="topbar">
    <h4 class="mb-0 fw-bold"><i class="bi bi-shield-lock me-2 text-primary"></i>Admin Panel</h4>
    <span class="badge bg-danger">Administrator</span>
</div>

<!-- Admin Stats -->
<div class="row g-4 mb-4">
    <div class="col-md-4">
        <div class="stat-card" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);">
            <i class="bi bi-people"></i>
            <div class="stat-value">{{ $stats['total_users'] }}</div>
            <div class="stat-label">Total Users</div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="stat-card" style="background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);">
            <i class="bi bi-file-post"></i>
            <div class="stat-value">{{ $stats['total_posts'] }}</div>
            <div class="stat-label">Total Posts</div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="stat-card" style="background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);">
            <i class="bi bi-share"></i>
            <div class="stat-value">{{ $stats['total_accounts'] }}</div>
            <div class="stat-label">Social Accounts</div>
        </div>
    </div>
</div>

<div class="row g-4 mb-4">
    <div class="col-md-4">
        <div class="stat-card" style="background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);">
            <i class="bi bi-calendar-event"></i>
            <div class="stat-value">{{ $stats['scheduled_posts'] }}</div>
            <div class="stat-label">Scheduled Posts</div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="stat-card" style="background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);">
            <i class="bi bi-check-circle"></i>
            <div class="stat-value">{{ $stats['published_posts'] }}</div>
            <div class="stat-label">Published Posts</div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="stat-card" style="background: linear-gradient(135deg, #ff0844 0%, #ffb199 100%);">
            <i class="bi bi-x-circle"></i>
            <div class="stat-value">{{ $stats['failed_posts'] }}</div>
            <div class="stat-label">Failed Posts</div>
        </div>
    </div>
</div>

<div class="row g-4">
    <!-- Recent Users -->
    <div class="col-lg-6">
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <span><i class="bi bi-people me-2"></i>Recent Users</span>
                <a href="{{ route('admin.users') }}" class="btn btn-sm btn-outline-primary">View All</a>
            </div>
            <div class="card-body p-0">
                <div class="table-responsive">
                    <table class="table table-hover mb-0">
                        <thead class="table-light">
                            <tr>
                                <th>Name</th>
                                <th>Email</th>
                                <th>Role</th>
                                <th>Joined</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($recent_users as $user)
                            <tr>
                                <td class="fw-semibold">{{ $user->name }}</td>
                                <td>{{ $user->email }}</td>
                                <td>
                                    <span class="badge {{ $user->isAdmin() ? 'bg-danger' : 'bg-info' }}">
                                        {{ ucfirst($user->role) }}
                                    </span>
                                </td>
                                <td class="text-muted" style="font-size: 0.875rem;">{{ $user->created_at->diffForHumans() }}</td>
                            </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

    <!-- Recent Posts -->
    <div class="col-lg-6">
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <span><i class="bi bi-file-post me-2"></i>Recent Posts</span>
                <a href="{{ route('admin.posts') }}" class="btn btn-sm btn-outline-primary">View All</a>
            </div>
            <div class="card-body p-0">
                <div class="table-responsive">
                    <table class="table table-hover mb-0">
                        <thead class="table-light">
                            <tr>
                                <th>User</th>
                                <th>Content</th>
                                <th>Status</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($recent_posts as $post)
                            <tr>
                                <td>{{ $post->user->name }}</td>
                                <td>{{ Str::limit($post->content, 40) }}</td>
                                <td>
                                    <span class="badge {{ $post->status_badge_class }}">
                                        {{ $post->status_label }}
                                    </span>
                                </td>
                            </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Recent Activity -->
<div class="card mt-4">
    <div class="card-header">
        <i class="bi bi-activity me-2"></i>Recent System Activity
    </div>
    <div class="card-body">
        @if($recent_activity->isEmpty())
            <div class="text-center py-4 text-muted">
                <p class="mb-0">No activity recorded yet</p>
            </div>
        @else
            <div class="table-responsive">
                <table class="table table-hover mb-0">
                    <thead class="table-light">
                        <tr>
                            <th>User</th>
                            <th>Action</th>
                            <th>Description</th>
                            <th>Time</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($recent_activity as $activity)
                        <tr>
                            <td>{{ $activity->user ? $activity->user->name : 'System' }}</td>
                            <td>
                                <span class="badge bg-secondary">{{ $activity->action }}</span>
                            </td>
                            <td>{{ $activity->description }}</td>
                            <td class="text-muted" style="font-size: 0.875rem;">{{ $activity->created_at->diffForHumans() }}</td>
                        </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        @endif
    </div>
</div>
@endsection
