@extends('layouts.app')

@section('title', 'Kriteria Penilaian')

@section('content')
<div class="card">
    <div class="card-header d-flex justify-content-between align-items-center">
        <h3 class="card-title">Master Kriteria Penilaian</h3>
        <a href="{{ route('kriteria.create') }}" class="btn btn-primary btn-sm">Tambah Kriteria</a>
    </div>
    <div class="card-body">
        @if(session('success'))
            <div class="alert alert-success">{{ session('success') }}</div>
        @endif
        
        <div class="alert alert-info">
            Total Bobot Saat Ini: <strong>{{ $totalBobot }}%</strong> 
            (Sistem penilaian ideal jika total bobot = 100%)
        </div>

        <table class="table table-bordered table-striped" id="example1">
            <thead>
                <tr>
                    <th width="50">No</th>
                    <th>Nama Kriteria</th>
                    <th>Bobot (%)</th>
                    <th width="150">Aksi</th>
                </tr>
            </thead>
            <tbody>
                @foreach($kriteria as $index => $k)
                <tr>
                    <td>{{ $index + 1 }}</td>
                    <td>{{ $k->nama_kriteria }}</td>
                    <td>{{ $k->bobot }}</td>
                    <td>
                        <a href="{{ route('kriteria.edit', $k->id) }}" class="btn btn-warning btn-sm">Edit</a>
                        <form action="{{ route('kriteria.destroy', $k->id) }}" method="POST" style="display:inline-block;">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('Yakin ingin menghapus kriteria ini?')">Hapus</button>
                        </form>
                    </td>
                </tr>
                @endforeach
            </tbody>
        </table>
    </div>
</div>
@endsection
