@extends('layouts.main')

@section('title', $title = 'Edit Data Pasien')

@section('content')
<div class="container pt-5 mb-5">
    <div class="row gy-4 shadow mb-4 bg-body-tertiary rounded">
        <h3 class="mb-0">Data Pasien</h3>
        <p class="text-success mt-0">Edit Data Pasien / {{ $pasien->nama }}</p>
    </div>
    <div class="row gy-4">
        <div class="pt-3 card">
            <div class="row">
                <div class="col-sm-12 pb-3 pt-3">
                    <a href="{{ route('pasien.index') }}" class="font-sm btn btn-warning text-white"><i class='bx bx-chevron-left'></i> Kembali</a>
                </div>
            </div>
            <form action="{{ route('pasien.update', $pasien) }}" method="POST">
                @csrf
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label for="nama">Nama</label>
                            <input type="text" class="form-control @error('nama') is-invalid @enderror" id="nama" name="nama" value="{{ old('nama', $pasien->nama) }}">
                            @error('nama')
                                <span class="invalid-feedback" role="alert">
                                    {{ $message }}
                                </span>
                            @enderror
                        </div>
                        <div class="form-group">
                            <label for="jenis_kelamin_id">Jenis Kelamin</label>
                            <select class="form-select @error('jenis_kelamin_id') is-invalid @enderror" name="jenis_kelamin_id" id="jenis_kelamin_id">
                                @foreach ($jenis_kelamin as $key => $value)
                                    <option value="{{ $value->id }}" {{ old('jenis_kelamin_id', $pasien->jenis_kelamin_id) == $value->id ? 'selected' : '' }}>{{ $value->jenis_kelamin }}</option>
                                @endforeach
                            </select>
                            @error('jenis_kelamin_id')
                                <span class="invalid-feedback" role="alert">
                                    {{ $message }}
                                </span>
                            @enderror
                        </div>
                        <div class="form-group">
                            <label for="umur">Umur</label>
                            <input type="text" class="form-control @error('umur') is-invalid @enderror" name="umur" id="umur" value="{{ old('umur', $pasien->umur) }}">
                            @error('umur')
                                <span class="invalid-feedback" role="alert">
                                    {{ $message }}
                                </span>
                            @enderror
                        </div>
                        <div class="form-group">
                            <label for="berat">Berat Badan (Kg)</label>
                            <input type="text" class="form-control @error('berat') is-invalid @enderror" id="berat" name="berat" value="{{ old('berat', $pasien->berat) }}">
                            @error('berat')
                                <span class="invalid-feedback" role="alert">
                                    {{ $message }}
                                </span>
                            @enderror
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label for="tinggi">Tinggi Badan (Cm)</label>
                            <input type="text" class="form-control @error('tinggi') is-invalid @enderror" id="tinggi" name="tinggi" value="{{ old('tinggi', $pasien->tinggi) }}">
                            @error('tinggi')
                                <span class="invalid-feedback" role="alert">
                                    {{ $message }}
                                </span>
                            @enderror
                        </div>
                        <div class="form-group">
                            <label for="aktivitas">Aktivitas</label>
                            <select class="form-select @error('aktivitas_id') is-invalid @enderror" name="aktivitas_id" id="aktivitas_id">
                                @foreach ($aktivitas as $key => $value)
                                    <option value="{{ $value->id }}" {{ old('aktivitas_id', $pasien->aktivitas_id) == $value->id ? 'selected' : '' }}>{{ $value->nama }}</option>
                                @endforeach
                            </select>
                            @error('aktivitas_id')
                                <span class="invalid-feedback" role="alert">
                                    {{ $message }}
                                </span>
                            @enderror
                        </div>
                        <div class="form-group">
                            <label for="kadar_gula">Kadar Gula Darah (mg/dl)</label>
                            <select class="form-select @error('kadar_gula_id') is-invalid @enderror" name="kadar_gula_id" id="kadar_gula_id">
                                @foreach ($kadar_gula as $key => $value)
                                    <option value="{{ $value->id }}" {{ old('kadar_gula_id', $pasien->kadar_gula_id) == $value->id ? 'selected' : '' }}>{{ $value->kadar_gula }}</option>
                                @endforeach
                            </select>
                            @error('kadar_gula_id')
                                <span class="invalid-feedback" role="alert">
                                    {{ $message }}
                                </span>
                            @enderror
                        </div>
                        <div class="form-group">
                            <label for="kebutuhan_kalori">Kebutuhan Kalori</label>
                            <select class="form-select @error('kebutuhan_kalori_id') is-invalid @enderror" name="kebutuhan_kalori_id" id="kebutuhan_kalori_id">
                                @foreach ($kebutuhan_kalori as $key => $value)
                                    <option value="{{ $value->id }}" {{ old('kebutuhan_kalori_id', $pasien->kebutuhan_kalori_id) == $value->id ? 'selected' : '' }}>{{ $value->kebutuhan_kalori }}</option>
                                @endforeach
                            </select>
                            @error('kebutuhan_kalori_id')
                                <span class="invalid-feedback" role="alert">
                                    {{ $message }}
                                </span>
                            @enderror
                        </div>
                    </div>
                </div>
                <div class="row mb-3">
                    <div class="text-end"> <!-- Menambahkan kelas text-end di sini -->
                        <button type="submit" class="btn btn-success"><i class='bx bx-save'></i>
                            Simpan</button>
                        <a href="{{ route('pasien.index') }}" class="btn btn-danger"><i class='bx bx-x'></i>
                            Batal</a>
                    </div>
                </div>  
            </form>
        </div>
    </div>
</div>
@endsection
