@extends('layouts.app')

@section('title', 'Edit Sub Kriteria')

@section('content')
<div class="container-fluid py-4">
    @if (session('success'))
    <div class="alert alert-success alert-dismissible fade show" role="alert">
        <div class="d-flex align-items-center">
            <i class="fas fa-check-circle mr-3"></i>
            <div>
                <strong>Sukses!</strong> {{ session('success') }}
            </div>
        </div>
        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
    @endif

    @if (session('error'))
    <div class="alert alert-danger alert-dismissible fade show" role="alert">
        <div class="d-flex align-items-center">
            <i class="fas fa-exclamation-circle mr-3"></i>
            <div>
                <strong>Error!</strong> {{ session('error') }}
            </div>
        </div>
        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
    @endif
    
    <div class="row justify-content-center">
        <div class="col-lg-10">
            <div class="card shadow-lg border-0" style="border-radius: 15px;">
                <div class="card-header bg-gradient-primary text-white d-flex justify-content-between align-items-center border-bottom-0">
                    <h4 class="mb-0 font-weight-bold">
                        <i class="fas fa-edit mr-2"></i>Edit Sub Kriteria
                    </h4>
                    <a href="{{ route('kriteria.subkriteria.index', $subkriteria->kriteria_id) }}" 
                       class="btn btn-light rounded-pill px-4 shadow-sm">
                        <i class="fas fa-arrow-left mr-2"></i> Kembali
                    </a>
                </div>
                
                <div class="card-body p-5">
                    <form action="{{ route('subkriteria.update', $subkriteria->id) }}" method="POST">
                        @csrf
                        @method('PUT')
                        
                        <!-- Kriteria Info -->
                        <div class="form-group mb-4">
                            <div class="alert alert-primary" role="alert" style="border-radius: 12px;">
                                <h5 class="alert-heading mb-2">
                                    <i class="fas fa-list-ul mr-2"></i> Nama Kriteria
                                </h5>
                                <hr>
                                <p class="mb-0 font-weight-bold">{{ $subkriteria->kriteria->nama_kriteria }}</p>
                            </div>
                            <input type="hidden" name="kriteria_id" value="{{ $subkriteria->kriteria_id }}">
                        </div>
                        
                        <!-- Nama Sub Kriteria -->
                        <div class="form-group mb-4">
                            <label class="form-label font-weight-bold mb-3 text-primary">
                                <i class="fas fa-tag mr-2"></i>Nama Sub Kriteria
                            </label>
                            <input type="text" 
                                   class="form-control rounded-pill py-3 px-4 shadow-sm border-0" 
                                   name="nama_subkriteria" 
                                   value="{{ $subkriteria->nama_subkriteria }}" 
                                   required
                                   style="background-color: #f8f9fa;">
                            @error('nama_subkriteria')
                                <div class="text-danger ml-3 mt-2">
                                    <i class="fas fa-exclamation-circle mr-1"></i>{{ $message }}
                                </div>
                            @enderror
                        </div>
                        
                        <!-- Nilai -->
                        <div class="form-group mb-4">
                            <label class="form-label font-weight-bold mb-3 text-primary">
                                <i class="fas fa-star-half-alt mr-2"></i>Nilai
                            </label>
                            <input type="number" 
                                    step="1" 
                                    min="0" 
                                    max="100"
                                    class="form-control rounded-pill py-3 px-4 shadow-sm border-0" 
                                    name="nilai"
                                    value="{{ number_format($subkriteria->nilai, 0, '', '') }}" 
                                    required
                                    style="background-color: #f8f9fa;">
                            <small class="form-text text-muted ml-3">
                                <i class="fas fa-info-circle mr-1"></i>Masukkan nilai bilangan bulat antara 0 - 100
                            </small>
                            @error('nilai')
                                <div class="text-danger ml-3 mt-2">
                                    <i class="fas fa-exclamation-circle mr-1"></i>{{ $message }}
                                </div>
                            @enderror
                        </div>
                        
                        <!-- Action Buttons -->
                        <div class="d-flex justify-content-end mt-5 pt-3">
                            <button type="reset" class="btn btn-outline-secondary rounded-pill px-4 mr-3 py-2 shadow-sm">
                                <i class="fas fa-redo mr-2"></i>Reset
                            </button>
                            <button type="submit" class="btn btn-primary rounded-pill px-4 py-2 shadow-sm">
                                <i class="fas fa-save mr-2"></i>Simpan Perubahan
                            </button>
                        </div>
                    </form>
                </div>

                <div class="card-footer text-muted small">
                    <i class="fas fa-history mr-1"></i> 
                    Terakhir diupdate: {{ $subkriteria->updated_at->format('d/m/Y H:i') }}
                </div>
                
            </div>
        </div>
    </div>
</div>

<style>
    body {
        background-color: #f8f9fa;
        font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    }
    .card {
        border: none;
        overflow: hidden;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    }
    .card-header {
        background: linear-gradient(135deg, #007a99 0%, #00b4db 100%);
    }
    .form-control {
        transition: all 0.3s ease;
    }
    .form-control:focus {
        box-shadow: 0 0 0 0.2rem rgba(0,122,153,0.25);
        border-color: rgba(0,122,153,0.5);
        transform: translateY(-2px);
    }
    .btn-primary {
        background-color: #007a99;
        border-color: #007a99;
        transition: all 0.3s ease;
    }
    .btn-primary:hover {
        background-color: #006680;
        border-color: #006680;
        transform: translateY(-2px);
    }
    .btn-outline-secondary {
        border-color: #007a99;
        color: #007a99;
        transition: all 0.3s ease;
    }
    .btn-outline-secondary:hover {
        background-color: #007a99;
        color: white;
        transform: translateY(-2px);
    }
    .form-label {
        letter-spacing: 0.5px;
    }
    .alert-primary {
        background-color: rgba(0, 122, 153, 0.1);
        border-left: 4px solid #007a99;
    }
</style>
@endsection