@extends('layouts.app')

@section('title', 'Dashboard Karyawan')

@section('css')
<style>
    :root {
        --primary-color: #005f73; /* Darker blue */
        --secondary-color: #0a9396; /* Teal */
        --accent-color: #94d2bd; /* Light teal */
        --light-color: #e9d8a6; /* Light yellow */
        --warning-color: #ca6702; /* Darker orange (reduced yellow) */
        --danger-color: #bb3e03; /* Dark red */
        --success-color: #28a745; /* Green */
    }
    
    .welcome-card {
        background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
        border-radius: 16px;
        color: white;
        box-shadow: 0 6px 20px rgba(0, 95, 115, 0.2);
        border: none;
        overflow: hidden;
        margin-bottom: 2rem;
        position: relative;
    }
    
    .welcome-card::before {
        content: "";
        position: absolute;
        top: -50%;
        right: -50%;
        width: 200%;
        height: 200%;
        background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 70%);
        transform: rotate(30deg);
    }
    
    .data-table-card {
        border-radius: 16px;
        overflow: hidden;
        box-shadow: 0 8px 25px rgba(0,0,0,0.08);
        border: none;
        margin-bottom: 2rem;
        background: white;
    }
    
    .data-table-card:hover {
        box-shadow: 0 12px 30px rgba(0,0,0,0.12);
    }
    
    .table-header {
        background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
        color: white;
        border: none;
        padding: 1.5rem;
    }
    
    .card-body-content {
        padding: 2rem;
    }
    
    .section-title {
        font-size: 1.2rem;
        font-weight: 600;
        margin-bottom: 0;
        letter-spacing: 0.5px;
    }
    
    .content-wrapper {
        padding: 2.5rem 0;
    }

    /* Verification Item Styles */
    .verification-item {
        background-color: white;
        padding: 1.5rem;
        border-radius: 12px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.05);
        margin-bottom: 1.5rem;
        transition: all 0.3s ease;
        border-left: 4px solid var(--accent-color);
    }
    
    .verification-item:hover {
        transform: translateY(-3px);
        box-shadow: 0 8px 20px rgba(0,0,0,0.1);
    }
    
    .verification-item-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0.75rem;
    }
    
    .verification-item-title {
        font-weight: 700;
        color: var(--primary-color);
        margin: 0;
        font-size: 1.2rem;
    }
    
    .verification-item-meta {
        font-size: 0.9rem;
        color: #6c757d;
        margin-bottom: 0.5rem;
    }
    
    .verification-item-dates {
        display: flex;
        flex-wrap: wrap;
        gap: 1rem;
        font-size: 0.85rem;
        margin-top: 1rem;
    }
    
    .verification-item-date {
        display: flex;
        align-items: center;
        background: #f8f9fa;
        padding: 0.5rem 0.75rem;
        border-radius: 20px;
    }
    
    .verification-item-date i {
        margin-right: 0.5rem;
        color: var(--primary-color);
    }
    
    .verification-stats {
        display: flex;
        flex-wrap: wrap;
        gap: 1rem;
        margin-top: 1rem;
    }
    
    .verification-stat {
        background-color: white;
        padding: 0.75rem;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.05);
        text-align: center;
        min-width: 120px;
        flex: 1;
    }
    
    .verification-stat-count {
        font-weight: 700;
        font-size: 1.2rem;
        margin-bottom: 0.25rem;
    }
    
    .verification-stat-label {
        font-size: 0.75rem;
        color: #6c757d;
    }
    
    .stat-waiting { color: var(--warning-color); }
    .stat-valid { color: var(--success-color); }
    .stat-invalid { color: var(--danger-color); }
    .stat-total { color: var(--primary-color); }
    
    /* Form Item Styles */
    .form-item {
        background-color: white;
        padding: 1.5rem;
        border-radius: 12px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.05);
        margin-bottom: 1.5rem;
        transition: all 0.3s ease;
        border-left: 4px solid var(--accent-color);
    }
    
    .form-item:hover {
        transform: translateY(-3px);
        box-shadow: 0 8px 20px rgba(0,0,0,0.1);
    }
    
    .form-item-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0.75rem;
    }
    
    .form-item-title {
        font-weight: 700;
        color: var(--primary-color);
        margin: 0;
        font-size: 1.2rem;
    }
    
    .form-item-meta {
        font-size: 0.9rem;
        color: #6c757d;
        margin-bottom: 0.5rem;
    }
    
    .form-item-dates {
        display: flex;
        flex-wrap: wrap;
        gap: 1rem;
        font-size: 0.85rem;
        margin-top: 1rem;
    }
    
    .form-item-date {
        display: flex;
        align-items: center;
        background: #f8f9fa;
        padding: 0.5rem 0.75rem;
        border-radius: 20px;
    }
    
    .form-item-date i {
        margin-right: 0.5rem;
        color: var(--primary-color);
    }
    
    /* Common Styles */
    .no-active-form {
        text-align: center;
        padding: 2.5rem 1.5rem;
        color: #6c757d;
        background-color: #f8fafc;
        border-radius: 12px;
        border: 1px dashed #dee2e6;
    }
    
    .no-active-form i {
        font-size: 2.5rem;
        margin-bottom: 1rem;
        color: #adb5bd;
    }
    
    .active-badge {
        background-color: var(--success-color);
        color: white;
        padding: 0.35rem 0.75rem;
        border-radius: 20px;
        font-size: 0.8rem;
        font-weight: 600;
        display: inline-flex;
        align-items: center;
    }
    
    .active-badge::before {
        content: "";
        display: inline-block;
        width: 8px;
        height: 8px;
        background-color: white;
        border-radius: 50%;
        margin-right: 6px;
        animation: pulse 1.5s infinite;
    }
    
    @keyframes pulse {
        0% { transform: scale(0.95); opacity: 1; }
        50% { transform: scale(1.1); opacity: 0.7; }
        100% { transform: scale(0.95); opacity: 1; }
    }
    
    /* Button styles */
    .btn-light {
        background-color: rgba(255,255,255,0.2);
        border-color: transparent;
        color: white;
        transition: all 0.3s ease;
        border-radius: 8px;
        padding: 0.5rem 1rem;
    }
    
    .btn-light:hover {
        background-color: rgba(255,255,255,0.3);
        color: white;
    }
    
    .dashboard-column {
        padding-left: 10px;
        padding-right: 10px;
    }
    
    .verification-column {
        padding-right: 5px;
    }
    
    .forms-column {
        padding-left: 5px;
    }
    
    /* Responsive adjustments */
    @media (max-width: 1200px) {
        .verification-stat {
            min-width: 100px;
        }
    }
    
    @media (max-width: 768px) {
        .card-body-content {
            padding: 1.5rem;
        }
        
        .verification-stat {
            min-width: calc(50% - 0.5rem);
        }
    }
    
    @media (max-width: 576px) {
        .verification-item-header,
        .form-item-header {
            flex-direction: column;
            align-items: flex-start;
        }
        
        .active-badge {
            margin-top: 0.5rem;
            margin-left: 0;
        }
        
        .verification-stat {
            min-width: 100%;
        }
    }
</style>
@endsection

@section('content')
<div class="content-wrapper">
    <div class="container-fluid">
        <!-- Welcome Card -->
        <div class="row">
            <div class="col-12">
                <div class="card welcome-card">
                    <div class="card-body">
                        <div class="row align-items-center">
                            <div class="col-md-8">
                                <h3 class="mb-3">Selamat Datang, {{ auth()->user()->name }}!</h3>
                                <p class="mb-0">Anda login sebagai <strong class="text-warning">Karyawan</strong></p>
                                <div class="mt-3">
                                    <span class="badge badge-light mr-2">
                                        <i class="fas fa-calendar-day mr-1"></i> {{ \Carbon\Carbon::now()->locale('id')->translatedFormat('l, d F Y') }}
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Main Content Cards -->
        <div class="row">
            <!-- Verifikasi Pengajuan Card -->
            <div class="col-lg-6 verification-column dashboard-column">
                <div class="card data-table-card h-100">
                    <div class="card-header table-header d-flex justify-content-between align-items-center">
                        <div>
                            <h6 class="section-title m-0">
                                <i class="fas fa-clipboard-check mr-2"></i> Verifikasi Pengajuan
                            </h6>
                            <p class="small mb-0 text-white">Kelola pengajuan UKT mahasiswa</p>
                        </div>
                        <a href="{{ route('admin.pengajuan') }}" class="btn btn-sm btn-light">
                            <i class="fas fa-eye mr-1"></i> Lihat Semua
                        </a>
                    </div>
                    <div class="card-body card-body-content">
                        @php
                            $activeForms = App\Models\Form::where('status', 'Dibuka')->get();
                        @endphp
                        
                        @if($activeForms->count() > 0)
                            <div class="form-list">
                                @foreach($activeForms as $form)
                                    @php
                                        $submissionCounts = [
                                            'total' => App\Models\PengajuanUkt::where('status_form_id', $form->id)->count(),
                                            'menunggu' => App\Models\PengajuanUkt::where('status_form_id', $form->id)
                                                ->where('status_validasi', 'menunggu')->count(),
                                            'valid' => App\Models\PengajuanUkt::where('status_form_id', $form->id)
                                                ->where('status_validasi', 'valid')->count(),
                                            'tidak_valid' => App\Models\PengajuanUkt::where('status_form_id', $form->id)
                                                ->where('status_validasi', 'tidak valid')->count()
                                        ];
                                    @endphp
                                    
                                    <div class="verification-item">
                                        <div class="verification-item-header">
                                            <h5 class="verification-item-title">
                                                <i class="fas fa-file-signature mr-2 text-primary"></i>
                                                {{ $form->nama_form }}
                                            </h5>
                                            <span class="active-badge">
                                                <i class="fas fa-circle mr-1"></i> AKTIF
                                            </span>
                                        </div>
                                        <div class="verification-item-meta">
                                            <span class="badge badge-primary mr-2">
                                                ID: {{ $form->id }}
                                            </span>
                                            <span class="badge badge-info">
                                                {{ ucfirst($form->jenis_form) }}
                                            </span>
                                        </div>
                                        
                                        <div class="verification-item-dates">
                                            <div class="verification-item-date">
                                                <i class="fas fa-door-open"></i>
                                                <span>Pembukaan: {{ $form->tanggal_pembuatan->format('d M Y') }}</span>
                                            </div>
                                            <div class="verification-item-date">
                                                <i class="fas fa-door-closed"></i>
                                                <span>Penutupan: {{ $form->tanggal_penutupan ? $form->tanggal_penutupan->format('d M Y') : '-' }}</span>
                                            </div>
                                            <div class="verification-item-date">
                                                <i class="fas fa-check-circle"></i>
                                                <span>Verifikasi: {{ $form->tanggal_verifikasi ? $form->tanggal_verifikasi->format('d M Y') : '-' }}</span>
                                            </div>
                                            <div class="verification-item-date">
                                                <i class="fas fa-bullhorn"></i>
                                                <span>Pengumuman: {{ $form->tanggal_pengumuman ? $form->tanggal_pengumuman->format('d M Y') : '-' }}</span>
                                            </div>
                                        </div>
                                        
                                        <div class="verification-stats">
                                            <div class="verification-stat">
                                                <div class="verification-stat-count stat-total">{{ $submissionCounts['total'] }}</div>
                                                <div class="verification-stat-label">Total Pengajuan</div>
                                            </div>
                                            <div class="verification-stat">
                                                <div class="verification-stat-count stat-waiting">{{ $submissionCounts['menunggu'] }}</div>
                                                <div class="verification-stat-label">Menunggu</div>
                                            </div>
                                            <div class="verification-stat">
                                                <div class="verification-stat-count stat-valid">{{ $submissionCounts['valid'] }}</div>
                                                <div class="verification-stat-label">Valid</div>
                                            </div>
                                            <div class="verification-stat">
                                                <div class="verification-stat-count stat-invalid">{{ $submissionCounts['tidak_valid'] }}</div>
                                                <div class="verification-stat-label">Tidak Valid</div>
                                            </div>
                                        </div>
                                        
                                        <div class="mt-3 d-flex flex-wrap">
                                            <a href="{{ route('admin.pengajuan') }}?status_form_id={{ $form->id }}" 
                                               class="btn btn-sm btn-outline-primary mr-2 mb-2">
                                                <i class="fas fa-list mr-1"></i> Semua Pengajuan
                                            </a>
                                        </div>
                                    </div>
                                @endforeach
                            </div>
                        @else
                            <div class="no-active-form">
                                <i class="fas fa-info-circle"></i>
                                <h5 class="mt-3 mb-2">Tidak ada formulir aktif</h5>
                                <p class="mb-0">Saat ini tidak ada formulir yang dibuka untuk pengajuan</p>
                            </div>
                        @endif
                    </div>
                </div>
            </div>

            <!-- Kelola Form Card -->
            <div class="col-lg-6 forms-column dashboard-column">
                <div class="card data-table-card h-100">
                    <div class="card-header table-header d-flex justify-content-between align-items-center">
                        <div>
                            <h6 class="section-title m-0">
                                <i class="fas fa-file-alt mr-2"></i> Formulir Aktif
                            </h6>
                            <p class="small mb-0 text-white">Daftar formulir yang sedang dibuka</p>
                        </div>
                        <a href="{{ route('form.pendaftaran') }}" class="btn btn-sm btn-light">
                            <i class="fas fa-eye mr-1"></i> Lihat Semua
                        </a>
                    </div>
                    <div class="card-body card-body-content">
                        @php
                            $activeForms = App\Models\Form::where('status', 'Dibuka')
                                ->orderBy('tahun', 'desc')
                                ->orderBy('semester', 'desc')
                                ->get();
                        @endphp
                        
                        @if($activeForms->count() > 0)
                            <div class="form-list">
                                @foreach($activeForms as $form)
                                    <div class="form-item">
                                        <div class="form-item-header">
                                            <h5 class="form-item-title">
                                                <i class="fas fa-file-signature mr-2 text-primary"></i>
                                                {{ $form->nama_form }}
                                            </h5>
                                            <span class="active-badge">
                                                <i class="fas fa-circle mr-1"></i> Aktif
                                            </span>
                                        </div>
                                        <div class="form-item-meta">
                                            <span class="badge badge-primary mr-2">
                                                {{ ucfirst($form->jenis_form) }}
                                            </span>
                                            <span class="badge badge-secondary">
                                                {{ $form->semester }} {{ $form->tahun }}
                                            </span>
                                        </div>
                                        <div class="form-item-dates">
                                            <div class="form-item-date">
                                                <i class="fas fa-calendar-plus"></i>
                                                <span class="fw-bold text-dark">Dibuka: {{ $form->tanggal_pembukaan ? \Carbon\Carbon::parse($form->tanggal_pembukaan)->format('d M Y') : '-' }}</span>
                                            </div>
                                             <div class="form-item-date">
                                                <i class="fas fa-calendar-plus"></i>
                                                <span class="fw-bold text-dark">Ditutup: {{ $form->tanggal_penutupan ? \Carbon\Carbon::parse($form->tanggal_pembukaan)->format('d M Y') : '-' }}</span>
                                            </div>
                                            <div class="form-item-date">
                                                <i class="fas fa-users"></i>
                                                <span>Pengajuan: {{ App\Models\PengajuanUkt::where('status_form_id', $form->id)->count() }}</span>
                                            </div>
                                        </div>
                                        <div class="mt-3 d-flex flex-wrap">
                                            <a href="{{ route('admin.pengajuan') }}?status_form_id={{ $form->id }}" class="btn btn-sm btn-outline-primary mr-2 mb-2">
                                                <i class="fas fa-list mr-1"></i> Lihat Pengajuan
                                            </a>
                                            <a href="{{ route('form.pendaftaran') }}" class="btn btn-sm btn-outline-secondary mb-2">
                                                <i class="fas fa-cog mr-1"></i> Kelola Form
                                            </a>
                                        </div>
                                    </div>
                                @endforeach
                            </div>
                        @else
                            <div class="no-active-form">
                                <i class="fas fa-info-circle"></i>
                                <h5 class="mt-3 mb-2">Tidak ada formulir aktif</h5>
                                <p class="mb-0">Saat ini tidak ada formulir yang dibuka untuk pengajuan</p>
                                <a href="{{ route('form.pendaftaran') }}" class="btn btn-primary mt-3">
                                    <i class="fas fa-plus mr-1"></i> Buat Formulir Baru
                                </a>
                            </div>
                        @endif
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection