@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 ="/data_obat/update/{{ $data->id }}" method="post">
                @method('patch')
                @csrf
                <div class="form-group">
                    <label>Nama Obat</label>
                    <input type="text" name="nama_obat" class="form-control @error('nama_obat')is-invalid @enderror"
                        value="{{ old('nama_obat', $data->nama_obat) }}">
                    @error('nama_obat')
                        <div class="invalid-feedback">
                            {{ $message }}
                        </div>
                    @enderror
                </div>
                <div class="form-group">
                    <label for="jenis_obat">Jenis Obat</label>
                    <select class="form-control @error('jenis_obat') is-invalid @enderror" name="jenis_obat"
                        id="jenis_obat">
                        <option value="" {{ old('jenis_obat') == '' ? 'selected' : '' }}>
                            ---
                            Pilih ---
                        </option>
                        <option value="Vitamin" {{ old('jenis_obat', $data->jenis_obat) == 'Vitamin' ? 'selected' : '' }}>
                            Vitamin
                        </option>
                        <option value="Imunisasi"
                            {{ old('jenis_obat', $data->jenis_obat) == 'Imunisasi' ? 'selected' : '' }}>
                            Imunisasi
                        </option>

                    </select>
                    @error('jenis_obat')
                        <div class="invalid-feedback">
                            {{ $message }}
                        </div>
                    @enderror
                </div>
                <div class="form-group">
                    <label>Keterangan</label>
                    <input type="text" name="keterangan_obat"
                        class="form-control @error('keterangan_obat')is-invalid @enderror"
                        value="{{ old('keterangan_obat', $data->keterangan_obat) }}">
                    @error('keterangan_obat')
                        <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
