@extends('layouts.siswa')

@section('title', 'Dashboard Siswa - MagangTime')
@section('page-title', 'Dashboard')

@section('content')
<div class="row g-3 mb-3">
    <!-- Profile Card -->
    <div class="col-12 col-lg-4">
        <div class="card h-100 shadow-sm border-0">
            <div class="card-header bg-dark text-white py-2 border-0">
                <h6 class="mb-0 fw-semibold"><i class="fas fa-user-graduate me-2"></i>Profil Siswa</h6>
            </div>
            <div class="card-body py-3">
                @if(Auth::user()->siswa)
                <div class="text-center">
                    <!-- Avatar Circle -->
                    <div class="bg-primary bg-opacity-10 rounded-circle mx-auto mb-2 d-flex align-items-center justify-content-center" style="width: 45px; height: 45px;">
                        <i class="fas fa-user-tie text-primary"></i>
                    </div>
                    
                    <!-- Student Info -->
                    <h6 class="fw-bold text-dark mb-1">{{ Auth::user()->siswa->nama_siswa }}</h6>
                    <p class="text-muted mb-2 small">{{ Auth::user()->siswa->sekolah->nama_sekolah }}</p>
                    
                    <!-- Period Info -->
                    <div class="border rounded p-2 bg-light">
                        <small class="text-muted d-block mb-1">Periode Magang</small>
                        <span class="badge bg-primary bg-opacity-10 text-primary px-2 py-1 small">
                            <i class="fas fa-calendar-alt me-1"></i>
                            {{ Auth::user()->siswa->mulai_magang->format('d/m/Y') }} - {{ Auth::user()->siswa->selesai_magang->format('d/m/Y') }}
                        </span>
                    </div>
                </div>
                @endif
            </div>
        </div>
    </div>

    <!-- Today Status -->
    <div class="col-12 col-lg-5">
        <div class="card h-100">
            <div class="card-header bg-success text-white py-2">
                <h6 class="mb-0"><i class="fas fa-calendar-day me-2"></i>Status Hari Ini</h6>
            </div>
            <div class="card-body py-3">
                @if($todayAttendance)
                    <div class="text-center mb-2">
                        <span class="badge bg-{{ $todayAttendance->status_badge }} px-3 py-1">
                            {{ ucfirst($todayAttendance->status) }}
                        </span>
                    </div>
                    <div class="row text-center g-2">
                        <div class="col-6">
                            <div class="bg-light rounded p-2">
                                <i class="fas fa-sign-in-alt text-success mb-1"></i>
                                <div class="h6 text-primary mb-1">
                                    {{ $todayAttendance->check_in_time ? $todayAttendance->check_in_time->format('H:i') : '–' }}
                                </div>
                                <small class="text-muted">Masuk</small>
                            </div>
                        </div>
                        <div class="col-6">
                            <div class="bg-light rounded p-2">
                                <i class="fas fa-sign-out-alt text-danger mb-1"></i>
                                <div class="h6 text-primary mb-1">
                                    {{ $todayAttendance->check_out_time ? $todayAttendance->check_out_time->format('H:i') : '–' }}
                                </div>
                                <small class="text-muted">Pulang</small>
                            </div>
                        </div>
                    </div>
                @else
                    <div class="text-center py-2">
                        <i class="fas fa-calendar-check fa-2x text-muted mb-2"></i>
                        <h6 class="text-muted mb-2">Belum Presensi</h6>
                        <p class="text-muted mb-2 small">Silakan lakukan presensi masuk</p>
                        <a href="{{ route('siswa.presensi.harian') }}" class="btn btn-primary btn-sm">
                            <i class="fas fa-calendar-check me-1"></i>Presensi Sekarang
                        </a>
                    </div>
                @endif
            </div>
        </div>
    </div>

    <!-- Working Hours -->
    <div class="col-12 col-lg-3">
        <div class="card h-100">
            <div class="card-header bg-info text-white py-2">
                <h6 class="mb-0"><i class="fas fa-clock me-2"></i>Jam Kerja</h6>
            </div>
            <div class="card-body py-3 text-center">
                <i class="fas fa-business-time fa-2x text-info mb-2"></i>
                <h5 class="fw-bold text-primary mb-1">08:00 - 16:00</h5>
                <small class="text-muted">WITA</small>
                <div class="mt-2">
                    <div class="bg-light rounded p-2">
                        <small class="text-muted">Total</small><br>
                        <strong class="small">8 Jam/Hari</strong>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Monthly Statistics -->
<div class="row g-3">
    <div class="col-6 col-md-4">
        <div class="card stats-card success">
            <div class="card-body text-center py-3">
                <i class="fas fa-check-circle fa-lg mb-2"></i>
                <h4 class="fw-bold mb-1">{{ $monthlyStats['hadir'] }}</h4>
                <p class="mb-1 small">Hari Hadir</p>
                <small class="text-muted">Bulan Ini</small>
            </div>
        </div>
    </div>
    <div class="col-6 col-md-4">
        <div class="card stats-card warning">
            <div class="card-body text-center py-3">
                <i class="fas fa-exclamation-circle fa-lg mb-2"></i>
                <h4 class="fw-bold mb-1">{{ $monthlyStats['izin'] }}</h4>
                <p class="mb-1 small">Hari Izin</p>
                <small class="text-muted">Bulan Ini</small>
            </div>
        </div>
    </div>
    <div class="col-12 col-md-4">
        <div class="card stats-card danger">
            <div class="card-body text-center py-3">
                <i class="fas fa-times-circle fa-lg mb-2"></i>
                <h4 class="fw-bold mb-1">{{ $monthlyStats['alfa'] }}</h4>
                <p class="mb-1 small">Hari Alfa</p>
                <small class="text-muted">Bulan Ini</small>
            </div>
        </div>
    </div>
</div>
@endsection