@extends('layout.app')

@section('content')
<div class="container">
    <h2 class="mb-4">Edit Relasi</h2>

    @if(session('error'))
        <div class="alert alert-danger">{{ session('error') }}</div>
    @endif

    <form method="POST" action="{{ route('relasi.update', $relasi->id) }}">
        @csrf
        @method('PUT')

        <div class="form-group mb-3">
            <label for="makanan_id">Makanan</label>
            <select name="makanan_id" class="form-control">
                @foreach($makanans as $makanan)
                    <option value="{{ $makanan->id }}" {{ $relasi->makanan_id == $makanan->id ? 'selected' : '' }}>
                        {{ $makanan->nama }}
                    </option>
                @endforeach
            </select>
        </div>

        <div class="form-group mb-3">
            <label for="komponen_id">Komponen</label>
            <select name="komponen_id" class="form-control">
                @foreach($komponens as $komponen)
                    <option value="{{ $komponen->id }}" {{ $relasi->komponen_id == $komponen->id ? 'selected' : '' }}>
                        {{ $komponen->nama }}
                    </option>
                @endforeach
            </select>
        </div>

        <div class="form-group mb-3">
            <label for="waktu_makan_id">Waktu Makan</label>
            <select name="waktu_makan_id" class="form-control">
                @foreach($waktuMakans as $waktu)
                    <option value="{{ $waktu->id }}" {{ $relasi->waktu_makan_id == $waktu->id ? 'selected' : '' }}>
                        {{ $waktu->nama }}
                    </option>
                @endforeach
            </select>
        </div>

        <button type="submit" class="btn btn-success">Simpan Perubahan</button>
        <a href="{{ route('relasi') }}" class="btn btn-secondary">Batal</a>
    </form>
</div>
@endsection
