@extends('layouts.main')
@section('container')
    <div class="card shadow mb-4">
        <div class="card-header py-3 text-center">
            <h5 class="m-0 font-weight-bold text-primary ">{{ $heading }}</h5>
        </div>

        <div class="card-body">
            <form action ="/status_periksa_ibu_hamil/{{ $data->id }}/update" method="post">
                @method('patch')
                @csrf
                <div class="form-group">
                    <label>Tanggal Pemeriksaan</label>
                    <input type="date" name="created_at" class="form-control @error('created_at')is-invalid @enderror"
                        value="{{ old('created_at') ?? ($data->created_at ? $data->created_at->format('Y-m-d') : '') }}">
                    @error('created_at')
                        <div class="invalid-feedback">
                            {{ $message }}
                        </div>
                    @enderror
                </div>
                {{-- <div class="form-group">
                    <label>Usia Hamil (Bulan)</label>
                    <input type="number" name="usia_hamil" class="form-control @error('usia_hamil')is-invalid @enderror"
                        value="{{ old('usia_hamil', $data->usia_hamil) }}">
                    @error('usia_hamil')
                        <div class="invalid-feedback">
                            {{ $message }}
                        </div>
                    @enderror
                </div> --}}
                <div class="form-group">
                    <label>Berat Badan (Kg)</label>
                    <input type="number" name="berat_badan" class="form-control @error('berat_badan')is-invalid @enderror"
                        value="{{ old('berat_badan', $data->berat_badan) }}">
                    @error('berat_badan')
                        <div class="invalid-feedback">
                            {{ $message }}
                        </div>
                    @enderror
                </div>
                <div class="form-group">
                    <label>Tekanan Darah</label>
                    <input type="number" name="tekanan_darah"
                        class="form-control @error('tekanan_darah')is-invalid @enderror"
                        value="{{ old('tekanan_darah', $data->tekanan_darah) }}">
                    @error('tekanan_darah')
                        <div class="invalid-feedback">
                            {{ $message }}
                        </div>
                    @enderror
                </div>
                <div class="form-group">
                    <label>Keluhan</label>
                    <input type="text" name="keluhan" class="form-control @error('keluhan')is-invalid @enderror"
                        value="{{ old('keluhan', $data->keluhan) }}">
                    @error('keluhan')
                        <div class="invalid-feedback">
                            {{ $message }}
                        </div>
                    @enderror
                </div>
                <div class="form-group">
                    <label for="vitamin_id">Vitamin</label>
                    <select class="form-control @error('vitamin_id') is-invalid @enderror" name="vitamin_id"
                        id="vitamin_id">
                        <option value="" {{ old('vitamin_id') == '' ? 'selected' : '' }}>---
                            Pilih ---
                        </option>
                        @foreach ($data_vitamin->where('jenis_obat', 'Vitamin') as $dv)
                            <option value="{{ $dv->id }}"
                                {{ old('vitamin_id', $data->vitamin_id) == $dv->id ? 'selected' : '' }}>
                                {{ $dv->nama_obat }}
                            </option>
                        @endforeach
                    </select>

                    @error('vitamin_id')
                        <div class="invalid-feedback">
                            {{ $message }}
                        </div>
                    @enderror
                </div>


                <div class="modal-footer">
                    <button class="btn btn-primary" type="submit">Update</button>
                </div>
                <hr>

            </form>
        </div>
    </div>
    <script>
        document.addEventListener('DOMContentLoaded', function() {

            var inputs = document.querySelectorAll('.form-control');
            inputs.forEach(function(input) {
                input.addEventListener('focus', function() {
                    this.classList.remove('is-invalid');
                    var feedback = this.parentNode.querySelector('.invalid-feedback');
                    if (feedback) {
                        feedback.style.display = 'none';
                    }
                });
            });
        });
    </script>
@endsection
