@extends('layouts.admin')

@section('title', 'Dashboard')

@section('content')
    <div class="row g-4">
        <div class="col-sm-6 col-xl-4">
            <div class="stat-card">
                <div class="stat-icon bg-primary-subtle text-primary"><i class="bi bi-grid-1x2"></i></div>
                <div>
                    <div class="stat-value">{{ $stats['services'] }}</div>
                    <div class="stat-label">Services</div>
                </div>
            </div>
        </div>
        <div class="col-sm-6 col-xl-4">
            <div class="stat-card">
                <div class="stat-icon bg-success-subtle text-success"><i class="bi bi-building"></i></div>
                <div>
                    <div class="stat-value">{{ $stats['projects'] }}</div>
                    <div class="stat-label">Projects</div>
                </div>
            </div>
        </div>
        <div class="col-sm-6 col-xl-4">
            <div class="stat-card">
                <div class="stat-icon bg-info-subtle text-info"><i class="bi bi-people"></i></div>
                <div>
                    <div class="stat-value">{{ $stats['clients'] }}</div>
                    <div class="stat-label">Clients</div>
                </div>
            </div>
        </div>
        <div class="col-sm-6 col-xl-4">
            <div class="stat-card">
                <div class="stat-icon bg-warning-subtle text-warning"><i class="bi bi-award"></i></div>
                <div>
                    <div class="stat-value">{{ $stats['certifications'] }}</div>
                    <div class="stat-label">Certifications</div>
                </div>
            </div>
        </div>
        <div class="col-sm-6 col-xl-4">
            <div class="stat-card">
                <div class="stat-icon bg-secondary-subtle text-secondary"><i class="bi bi-download"></i></div>
                <div>
                    <div class="stat-value">{{ $stats['downloads'] }}</div>
                    <div class="stat-label">Downloads</div>
                </div>
            </div>
        </div>
        <div class="col-sm-6 col-xl-4">
            <a href="{{ route('admin.messages.index') }}" class="text-decoration-none">
                <div class="stat-card">
                    <div class="stat-icon {{ $stats['unreadMessages'] > 0 ? 'bg-danger-subtle text-danger' : 'bg-secondary-subtle text-secondary' }}"><i class="bi bi-envelope"></i></div>
                    <div>
                        <div class="stat-value">{{ $stats['unreadMessages'] }}<span class="fs-6 text-muted">/{{ $stats['totalMessages'] }}</span></div>
                        <div class="stat-label">Unread Messages</div>
                    </div>
                </div>
            </a>
        </div>
    </div>

    <div class="card mt-4">
        <div class="card-header bg-white">
            <h6 class="mb-0"><i class="bi bi-clock-history me-2"></i>Recent Contact Messages</h6>
        </div>
        <div class="card-body p-0">
            <table class="table table-hover align-middle mb-0">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Email</th>
                        <th>Subject</th>
                        <th>Date</th>
                        <th>Status</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($recentMessages as $message)
                        <tr>
                            <td class="fw-semibold">{{ $message->name }}</td>
                            <td>{{ $message->email }}</td>
                            <td>{{ Str::limit($message->subject ?: '—', 30) }}</td>
                            <td>{{ $message->created_at->diffForHumans() }}</td>
                            <td>
                                @if($message->is_read)
                                    <span class="badge bg-secondary">Read</span>
                                @else
                                    <span class="badge bg-danger">Unread</span>
                                @endif
                            </td>
                            <td><a href="{{ route('admin.messages.show', $message) }}" class="btn btn-sm btn-outline-primary">View</a></td>
                        </tr>
                    @empty
                        <tr><td colspan="6" class="text-center text-muted py-4">No contact messages yet.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
@endsection
