@extends('admin.layouts.app')

@section('content')

{{-- STYLES --}}
<style>
/* Reset & Base */
:root {
    --bg-main: #f4f7fb;
    --card-bg: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-faint: #cbd5e1;
    --border-color: #e2e8f0;
    
    --blue-dark: #0D215C;
    --blue-mid: #2563eb;
    --blue-pale: #bfdbfe;
    --blue-ultra: #eff6ff;

    --green: #10b981;
    --red: #ef4444;
    --amber: #f59e0b;
}

.sa-container {
    padding: 30px;
    background: var(--bg-main);
    min-height: calc(100vh - 70px);
    font-family: 'Outfit', 'Segoe UI', sans-serif;
}

.sa-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.sa-title-wrap {
    display: flex;
    flex-direction: column;
}

.sa-title-wrap h1 {
    font-size: 32px;
    font-weight: 900;
    color: #000;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: -1px;
    position: relative;
    display: inline-block;
}

.sa-title-wrap h1::after {
    content: "";
    display: block;
    width: 50px;
    height: 4px;
    background: #000;
    margin-top: 5px;
}

.btn-back {
    text-decoration: none;
    font-size: 14px;
    color: var(--blue-mid);
    font-weight: 600;
    background: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    transition: all 0.3s ease;
}

.btn-back:hover {
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}

/* Cards Grid */
.news-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
}

.news-card {
    background: var(--card-bg);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.04);
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(226,232,240,0.6);
    position: relative;
}

.news-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 30px rgba(0,0,0,0.08);
}

.news-card a:hover .news-title {
    color: var(--blue-mid);
}

.news-image {
    width: 100%;
    height: 180px;
    object-fit: cover;
    background-color: #e2e8f0;
}

.news-content {
    padding: 20px;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.news-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 12px;
    text-transform: uppercase;
}

.news-meta svg {
    width: 14px;
    height: 14px;
    opacity: 0.7;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.news-title {
    font-size: 18px;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.4;
    margin: 0 0 12px 0;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.news-footer {
    margin-top: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.status-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.status-badge.selesai { background: #ecfdf5; color: #059669; }
.status-badge.proses { background: #eff6ff; color: #2563eb; }
.status-badge.batal { background: #fef2f2; color: #dc2626; }

.btn-restore {
    background: transparent;
    border: none;
    color: var(--blue-mid);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 8px;
    transition: all 0.2s;
}

.btn-restore:hover {
    background: var(--blue-ultra);
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    background: #fff;
    border-radius: 20px;
    border: 1px dashed var(--border-color);
    color: var(--text-muted);
}

@media (max-width: 768px) {
    .sa-container {
        padding: 15px;
    }
    .sa-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    .btn-back {
        align-self: flex-start;
    }
    .news-grid {
        grid-template-columns: 1fr;
    }
}
</style>

{{-- ICONS --}}
<svg width="0" height="0" style="position:absolute; display:none;">
    <symbol id="ic-calendar" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
        <rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect>
        <line x1="16" y1="2" x2="16" y2="6"></line>
        <line x1="8" y1="2" x2="8" y2="6"></line>
        <line x1="3" y1="10" x2="21" y2="10"></line>
    </symbol>
    <symbol id="ic-eye" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
        <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path>
        <circle cx="12" cy="12" r="3"></circle>
    </symbol>
    <symbol id="ic-restore" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
        <path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/>
        <path d="M3 3v5h5"/>
    </symbol>
</svg>

<div class="sa-container">
    <div class="sa-header">
        <div class="sa-title-wrap">
            <h1>Arsip Laporan</h1>
        </div>
        <a href="{{ route('admin.superadmin.dashboard') }}" class="btn-back">&larr; Kembali ke Dashboard</a>
    </div>

    @if(session('success'))
        <div style="padding:14px 18px; background:#ecfdf5; border:1px solid #a7f3d0; border-radius:12px; color:#047857; font-size:14px; font-weight:600; margin-bottom:24px; display:flex; align-items:center; gap:10px;">
            <svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7"></path></svg>
            {{ session('success') }}
        </div>
    @endif
    @if(session('error'))
        <div style="padding:14px 18px; background:#fef2f2; border:1px solid #fecaca; border-radius:12px; color:#dc2626; font-size:14px; font-weight:600; margin-bottom:24px; display:flex; align-items:center; gap:10px;">
            <svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12"></path></svg>
            {{ session('error') }}
        </div>
    @endif

    <div class="news-grid">
        @forelse($activities as $act)
            @php
                // Generate a consistent dummy views count based on ID
                $views = ($act->id * 17) % 1000 + 50; 
                
                // Array of default placeholder images for variety
                $placeholders = [
                    'https://images.unsplash.com/photo-1454165804606-c3d57bc86b40?q=80&w=600&auto=format&fit=crop', // office/planning
                    'https://images.unsplash.com/photo-1517048676732-d65bc937f952?q=80&w=600&auto=format&fit=crop', // teamwork
                    'https://images.unsplash.com/photo-1552664730-d307ca884978?q=80&w=600&auto=format&fit=crop', // meeting
                    'https://images.unsplash.com/photo-1507537297725-24a1c029d3ca?q=80&w=600&auto=format&fit=crop', // paper/desk
                    'https://images.unsplash.com/photo-1581091226825-a6a2a5aee158?q=80&w=600&auto=format&fit=crop'  // tech/research
                ];
                $imgSrc = $placeholders[$act->id % count($placeholders)];
            @endphp
            <div class="news-card">
                <a href="{{ route('admin.superadmin.kegiatan.show', $act->id) }}" style="text-decoration: none; color: inherit; display: flex; flex-direction: column; flex-grow: 1;">
                    <img src="{{ $imgSrc }}" alt="Laporan Image" class="news-image" loading="lazy">
                    <div class="news-content" style="padding-bottom: 0; flex-grow: 1;">
                        <div class="news-meta">
                            <div class="meta-item">
                                <svg><use href="#ic-calendar"/></svg>
                                <span>{{ \Carbon\Carbon::parse($act->tanggal)->translatedFormat('d M Y') }}</span>
                            </div>
                            <span>&bull;</span>
                            <div class="meta-item">
                                <svg><use href="#ic-eye"/></svg>
                                <span>{{ $views }}</span>
                            </div>
                        </div>
                        
                        <h3 class="news-title" title="{{ $act->nama_kegiatan }}">{{ $act->nama_kegiatan }}</h3>
                    </div>
                </a>
                
                <div class="news-content" style="padding-top: 10px; flex-grow: 0;">
                    <div class="news-footer">
                        <span class="status-badge {{ $act->status == 'selesai' ? 'selesai' : ($act->status == 'dibatalkan' ? 'batal' : 'proses') }}">
                            {{ strtoupper(str_replace('_', ' ', $act->status)) }}
                        </span>
                        
                        <form action="{{ route('admin.superadmin.kegiatan.archive', $act->id) }}" method="POST" style="margin: 0;">
                            @csrf
                            <button type="submit" class="btn-restore" title="Kembalikan Laporan">
                                <svg width="16" height="16"><use href="#ic-restore"/></svg>
                                Restore
                            </button>
                        </form>
                    </div>
                </div>
            </div>
        @empty
            <div class="empty-state">
                <svg width="64" height="64" style="color:var(--text-faint); margin-bottom:15px;" fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 002-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"></path></svg>
                <h3>Belum ada arsip laporan</h3>
                <p>Laporan yang diarsipkan akan muncul di sini.</p>
            </div>
        @endforelse
    </div>

    @if($activities->hasPages())
    <div style="margin-top:40px; display:flex; justify-content:center;">
        {{ $activities->links('pagination::bootstrap-4') }}
    </div>
    @endif
</div>
@endsection
