@extends('layouts.app')

@section('title', 'Hasil Perhitungan SAW')

@section('content')
<div class="container-fluid">
    <!-- Header with Back Button -->
    <div class="d-sm-flex align-items-center justify-content-between mb-4">
        <h1 class="h3 mb-0 text-gray-800">
            <i class="fas fa-calculator text-primary mr-2"></i>Hasil Perhitungan SAW
        </h1>
        <a href="{{ route('admin.penilaian.index') }}" class="d-none d-sm-inline-block btn btn-sm btn-outline-secondary shadow-sm">
            <i class="fas fa-arrow-left fa-sm mr-1"></i> Kembali
        </a>
    </div>

    <!-- Student Information Card -->
<div class="card shadow-sm border-0 mb-4">
    <div class="card-header bg-white py-3 d-flex align-items-center justify-content-between border-bottom">
        <div class="d-flex align-items-center">
            <div class="icon-circle bg-primary mr-3">
                <i class="fas fa-user-graduate text-white"></i>
            </div>
            <h5 class="m-0 font-weight-bold text-gray-800">Informasi Mahasiswa</h5>
        </div>
    </div>
    <div class="card-body">
        <div class="row">
            <!-- Left Column -->
            <div class="col-md-6 border-right">
                <div class="d-flex align-items-center mb-4">
                    <div class="avatar bg-light-primary text-primary rounded-circle mr-3">
                    </div>
                    <div>
                        <h4 class="mb-0 font-weight-bold">{{ $pengajuan->mahasiswa->user->name }}</h4>
                        <small class="text-muted">{{ $pengajuan->mahasiswa->nim }}</small>
                    </div>
                </div>
                
                <div class="pl-4">
                    <div class="info-item mb-3">
                        <div class="text-muted small">Program Studi</div>
                        <div class="font-weight-bold">{{ $pengajuan->mahasiswa->program_studi }}</div>
                    </div>
                    <div class="info-item">
                        <div class="text-muted small">Email</div>
                        <div class="font-weight-bold text-truncate">{{ $pengajuan->mahasiswa->user->email }}</div>
                    </div>
                </div>
            </div>
            
            <!-- Right Column -->
            <div class="col-md-6">
                <div class="pl-md-4 pl-0">
                    <div class="info-item mb-3">
                        <div class="text-muted small">UKT Saat Ini</div>
                        <div class="font-weight-bold text-primary">
                            Rp {{ number_format($pengajuan->ukt_saat_ini, 0, ',', '.') }}
                        </div>
                    </div>
                    <div class="info-item mb-3">
                        <div class="text-muted small">Tanggal Pengajuan</div>
                        <div class="font-weight-bold">
                            <i class="far fa-calendar-alt mr-1 text-gray-500"></i>
                            {{ $pengajuan->created_at->translatedFormat('d F Y') }}
                        </div>
                    </div>
                    <div class="info-item">
                        <div class="text-muted small">Jenis Pengajuan</div>
                        <div>
                            <span class="badge badge-{{ $pengajuan->jenis_pengajuan == 'penurunan' ? 'info' : 'warning' }}">
                                <i class="fas fa-{{ $pengajuan->jenis_pengajuan == 'penurunan' ? 'arrow-down' : 'calendar' }} mr-1"></i>
                                {{ ucfirst($pengajuan->jenis_pengajuan) }}
                            </span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

    <!-- Calculation Results -->
    <div class="card shadow mb-4">
        <div class="card-header py-3 bg-white">
            <h6 class="m-0 font-weight-bold text-primary">
                <i class="fas fa-chart-bar mr-2"></i>Hasil Perhitungan
            </h6>
        </div>
        <div class="card-body">
            <!-- Summary Cards -->
            <div class="row mb-4">
                <div class="col-xl-4 col-md-6 mb-4">
                    <div class="card border-left-primary h-100 py-2">
                        <div class="card-body">
                            <div class="row no-gutters align-items-center">
                                <div class="col mr-2">
                                    <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
                                        Nilai Preferensi
                                    </div>
                                    <div class="h5 mb-0 font-weight-bold text-gray-800">
                                        {{ number_format($hasil['preference_value'], 6) }}
                                    </div>
                                </div>
                                <div class="col-auto">
                                    <i class="fas fa-percent fa-2x text-gray-300"></i>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-xl-4 col-md-6 mb-4">
                    <div class="card border-left-success h-100 py-2">
                        <div class="card-body">
                            <div class="row no-gutters align-items-center">
                                <div class="col mr-2">
                                    <div class="text-xs font-weight-bold text-success text-uppercase mb-1">
                                        Rekomendasi UKT
                                    </div>
                                    <div class="h5 mb-0 font-weight-bold text-gray-800">
                                        @if($pengajuan->jenis_pengajuan == 'penurunan')
                                            {{ $hasil['preference_value'] >= 0.65 ? 'Dapat Penurunan' : 'UKT Tetap' }}
                                        @else
                                            {{ $hasil['preference_value'] >= 0.75 ? 'Dapat Pengangsuran' : 'Tidak Dapat' }}
                                        @endif
                                    </div>
                                </div>
                                <div class="col-auto">
                                    <i class="fas fa-check-circle fa-2x text-gray-300"></i>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-xl-4 col-md-6 mb-4">
                    <div class="card border-left-info h-100 py-2">
                        <div class="card-body">
                            <div class="row no-gutters align-items-center">
                                <div class="col mr-2">
                                    <div class="text-xs font-weight-bold text-info text-uppercase mb-1">
                                        Status Validasi
                                    </div>
                                    <div class="h5 mb-0 font-weight-bold text-gray-800">
                                        <span class="badge badge-{{ $pengajuan->status_validasi == 'valid' ? 'success' : 'warning' }}">
                                            {{ ucfirst($pengajuan->status_validasi) }}
                                        </span>
                                    </div>
                                </div>
                                <div class="col-auto">
                                    <i class="fas fa-info-circle fa-2x text-gray-300"></i>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Criteria Table -->
            <div class="table-responsive">
                <table class="table table-bordered" width="100%" cellspacing="0">
                    <thead class="bg-gray-100">
                        <tr>
                            <th class="text-center align-middle">Kriteria</th>
                            <th class="text-center align-middle">Tipe</th>
                            <th class="text-center align-middle">Bobot</th>
                            <th class="text-center align-middle">Nilai</th>
                            <th class="text-center align-middle">Normalisasi</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($kriterias as $kriteria_id => $kriteria)
                            @php
                                $nilai = $hasil['decision_matrix'][$kriteria_id] ?? null;
                                $normalisasi = $hasil['normalized_matrix'][$kriteria_id] ?? null;
                            @endphp
                            <tr>
                                <td class="font-weight-bold">{{ $kriteria->nama_kriteria }}</td>
                                <td class="text-center">
                                    <span class="badge badge-{{ $kriteria->attribut == 'benefit' ? 'success' : 'danger' }}">
                                        {{ ucfirst($kriteria->attribut) }}
                                    </span>
                                </td>
                                <td class="text-center">{{ ($kriteria->bobot * 100) }}%</td>
                                <td class="text-center">
                                    @if(isset($nilai))
                                        <span class="badge badge-primary">{{ $nilai }}</span>
                                    @else
                                        <span class="text-muted">-</span>
                                    @endif
                                </td>
                                <td class="text-center">
                                    @if(isset($normalisasi))
                                        <span class="badge badge-info text-white">{{ number_format($normalisasi, 4) }}</span>
                                    @else
                                        <span class="text-muted">-</span>
                                    @endif
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>

            <!-- Threshold Information -->
            <div class="mt-4 p-3 bg-light rounded">
                <h6 class="font-weight-bold text-dark mb-2">
                    <i class="fas fa-info-circle text-primary mr-2"></i>Ketentuan Rekomendasi
                </h6>
                <p class="mb-0">
                    @if($pengajuan->jenis_pengajuan == 'penurunan')
                        <span class="font-weight-bold">Penurunan UKT:</span> Nilai preferensi ≥ 0.65
                    @else
                        <span class="font-weight-bold">Pengangsuran UKT:</span> Nilai preferensi ≥ 0.75
                    @endif
                </p>
            </div>
        </div>
    </div>
</div>
@endsection

@push('styles')
<style>
    .icon-circle {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .info-item {
        padding: 0.5rem 0;
    }
    
    .border-right {
        border-right: 1px solid #e3e6f0 !important;
    }
    
    .bg-light-primary {
        background-color: #e3f2fd;
    }
    
    .card-header {
        border-bottom: 1px solid rgba(0,0,0,.05);
    }
    
    .badge {
        font-weight: 500;
        letter-spacing: 0.5px;
    }
    .table th {
        white-space: nowrap;
        background-color: #f8f9fc;
    }
    .border-left-primary {
        border-left: 0.25rem solid #4e73df !important;
    }
    .border-left-success {
        border-left: 0.25rem solid #1cc88a !important;
    }
    .border-left-info {
        border-left: 0.25rem solid #36b9cc !important;
    }
</style>
@endpush