@extends('layouts.main')
@section('container')
    @if (session()->has('success'))
        <div class="alert alert-success alert-dismissible show fade">
            <div class="alert-body">
                <button class="close" data-dismiss="alert">
                    <span>×</span>
                </button>
                {{ session('success') }}
            </div>
        </div>
    @endif
    <div class="card shadow mb-4">
        {{-- <div class="card-header py-3 d-flex justify-content-between align-items-center">
            <h6 class="m-0 font-weight-bold text-primary">{{ $heading2 }} {{ $data->nama_ibu }}</h6>
            <a href="#" class="btn btn-primary btn-icon-split btn-sm">
                <span class="icon text-white-50">
                    <i class="fas fa-plus"></i>
                </span>
                <span class="text">Tambah</span>
            </a>
        </div> --}}
        <div class="card m-3">
            <div class="row no-gutters">
                <div class="col-md-2 bg-gray-100 d-flex justify-content-center align-items-center ">
                    <img src="{{ asset('img/avatar-1.png') }}" class="card-img rounded-circle mb-2 mt-2" style="width: 25vh"
                        alt="...">
                </div>

                <div class="col-md-10">
                    <div class="card-body">

                        <h5 class="card-title text-center" style="text-transform: uppercase">Ibu {{ $data->nama_ibu }}
                        </h5>
                        <hr>
                        <div class="row ">
                            <div class="col-md-6 mb-2">
                                <div class="card bg-gray-100 p-2">
                                    <p class="card-text">
                                        Biodata :
                                    </p>
                                    <ul class="aligned-list">
                                        <li>
                                            <span class="v1">NIK Ibu</span>
                                            <span>:</span>
                                            <span>{{ $data->nik_ibu }}</span>
                                        </li>
                                        <li>
                                            <span class="v1">Tanggal Lahir Ibu</span>
                                            <span>:</span>
                                            <span>{{ \Carbon\Carbon::parse($data->tanggal_lahir_ibu)->format('d - F - Y') }}</span>
                                        </li>
                                        <li>
                                            <span class="v1">Nama Ibu</span>
                                            <span>:</span>
                                            <span>{{ $data->nama_ibu }}</span>
                                        </li>
                                        <li>
                                            <span class="v1">Umur Ibu</span>
                                            <span>:</span>
                                            <span>{{ $data->umur_ibu }}</span>
                                        </li>
                                        <li>
                                            <span class="v1">Tanggal Lahir Ayah</span>
                                            <span>:</span>
                                            <span>{{ \Carbon\Carbon::parse($data->tanggal_lahir_ayah)->format('d - F - Y') }}</span>
                                        </li>

                                        <li>
                                            <span class="v1">Nama Ayah</span>
                                            <span>:</span>
                                            <span>{{ $data->nama_ayah }}</span>
                                        </li>
                                        <li>
                                            <span class="v1">Umur Ayah</span>
                                            <span>:</span>
                                            <span>{{ $data->umur_ayah }}</span>
                                        </li>

                                        <li>
                                            <span class="v1">Alamat</span>
                                            <span>:</span>
                                            <span>{{ $data->alamat }}</span>
                                        </li>
                                        <li>
                                            <span class="v1">Status Ibu</span>
                                            <span>:</span>
                                            <span>{{ $data->status_ibu }}</span>
                                        </li>
                                        <li>
                                            <span class="v1">Status Ayah</span>
                                            <span>:</span>
                                            <span>{{ $data->status_ayah }}</span>
                                        </li>
                                    </ul>
                                    @can('admin_is')
                                        <p class="card-text ">
                                            <button id="showFormBtnv2" class="btn btn-primary btn-sm float-right">
                                                <span class="icon text-white">
                                                    <i class="far fa-edit"></i>
                                                </span>
                                            </button>
                                        </p>
                                    @endcan
                                    <div id="formContainerv2" style="display: none">
                                        <hr>
                                        <form action ="/edit_biodata/{{ $data->id }}/edit" method="post">
                                            @method('patch')
                                            @csrf
                                            <div class="form-group">
                                                <label>NIK Ibu</label>
                                                <input type="number" name="nik_ibu"
                                                    class="form-control @error('nik_ibu')is-invalid @enderror"
                                                    value="{{ old('nik_ibu', $data->nik_ibu) }}">
                                                @error('nik_ibu')
                                                    <div class="invalid-feedback">
                                                        {{ $message }}
                                                    </div>
                                                @enderror
                                            </div>
                                            <div class="form-group">
                                                <label>Tanggal Lahir Ibu</label>
                                                <input type="date" name="tanggal_lahir_ibu"
                                                    class="form-control @error('tanggal_lahir_ibu')is-invalid @enderror"
                                                    value="{{ old('tanggal_lahir_ibu', $data->tanggal_lahir_ibu) }}">
                                                @error('tanggal_lahir_ibu')
                                                    <div class="invalid-feedback">
                                                        {{ $message }}
                                                    </div>
                                                @enderror
                                            </div>
                                            <div class="form-group">
                                                <label>Nama Ibu</label>
                                                <input type="text" name="nama_ibu"
                                                    class="form-control @error('nama_ibu')is-invalid @enderror"
                                                    value="{{ old('nama_ibu', $data->nama_ibu) }}">
                                                @error('nama_ibu')
                                                    <div class="invalid-feedback">
                                                        {{ $message }}
                                                    </div>
                                                @enderror
                                            </div>
                                            {{-- <div class="form-group">
                                                <label>Umur Ibu</label>
                                                <input type="number" name="umur_ibu"
                                                    class="form-control @error('umur_ibu')is-invalid @enderror"
                                                    value="{{ old('umur_ibu', $data->umur_ibu) }}">
                                                @error('umur_ibu')
                                                    <div class="invalid-feedback">
                                                        {{ $message }}
                                                    </div>
                                                @enderror
                                            </div> --}}
                                            <div class="form-group">
                                                <label>Tanggal Lahir Ayah</label>
                                                <input type="date" name="tanggal_lahir_ayah"
                                                    class="form-control @error('tanggal_lahir_ayah')is-invalid @enderror"
                                                    value="{{ old('tanggal_lahir_ayah', $data->tanggal_lahir_ayah) }}">
                                                @error('tanggal_lahir_ayah')
                                                    <div class="invalid-feedback">
                                                        {{ $message }}
                                                    </div>
                                                @enderror
                                            </div>
                                            <div class="form-group">
                                                <label>Nama Ayah</label>
                                                <input type="text" name="nama_ayah"
                                                    class="form-control @error('nama_ayah')is-invalid @enderror"
                                                    value="{{ old('nama_ayah', $data->nama_ayah) }}">
                                                @error('nama_ayah')
                                                    <div class="invalid-feedback">
                                                        {{ $message }}
                                                    </div>
                                                @enderror
                                            </div>
                                            {{-- <div class="form-group">
                                                <label>Umur Ayah</label>
                                                <input type="text" name="umur_ayah"
                                                    class="form-control @error('umur_ayah')is-invalid @enderror"
                                                    value="{{ old('umur_ayah', $data->umur_ayah) }}">
                                                @error('umur_ayah')
                                                    <div class="invalid-feedback">
                                                        {{ $message }}
                                                    </div>
                                                @enderror
                                            </div> --}}
                                            <div class="form-group">
                                                <label>Alamat</label>
                                                <input type="text" name="alamat"
                                                    class="form-control @error('alamat')is-invalid @enderror"
                                                    value="{{ old('alamat', $data->alamat) }}">
                                                @error('alamat')
                                                    <div class="invalid-feedback">
                                                        {{ $message }}
                                                    </div>
                                                @enderror
                                            </div>
                                            <div class="form-group">
                                                <label for="status_ibu">Status Ibu</label>
                                                <select class="form-control @error('status_ibu') is-invalid @enderror"
                                                    name="status_ibu" id="status_ibu">
                                                    <option value="" {{ old('status_ibu') == '' ? 'selected' : '' }}>
                                                        ---
                                                        Pilih ---
                                                    </option>
                                                    <option value="Hamil"
                                                        {{ old('status_ibu', $data->status_ibu) == 'Hamil' ? 'selected' : '' }}>
                                                        Hamil
                                                    </option>
                                                    <option value="Sudah Melahirkan"
                                                        {{ old('status_ibu', $data->status_ibu) == 'Sudah Melahirkan' ? 'selected' : '' }}>
                                                        Sudah Melahirkan
                                                    </option>
                                                    <option value="Meninggal"
                                                        {{ old('status_ibu', $data->status_ibu) == 'Meninggal' ? 'selected' : '' }}>
                                                        Meninggal
                                                    </option>
                                                </select>
                                                @error('status_ibu')
                                                    <div class="invalid-feedback">
                                                        {{ $message }}
                                                    </div>
                                                @enderror
                                            </div>
                                            <div class="form-group">
                                                <label for="status_ayah">Status Ayah</label>
                                                <select class="form-control @error('status_ayah') is-invalid @enderror"
                                                    name="status_ayah" id="status_ayah">
                                                    <option value=""
                                                        {{ old('status_ayah') == '' ? 'selected' : '' }}>
                                                        ---
                                                        Pilih ---
                                                    </option>
                                                    <option value="Masih Hidup"
                                                        {{ old('status_ayah', $data->status_ayah) == 'Masih Hidup' ? 'selected' : '' }}>
                                                        Masih Hidup
                                                    </option>
                                                    <option value="Cerai"
                                                        {{ old('status_ayah', $data->status_ayah) == 'Cerai' ? 'selected' : '' }}>
                                                        Cerai
                                                    </option>
                                                    <option value="Meninggal"
                                                        {{ old('status_ayah', $data->status_ayah) == 'Meninggal' ? 'selected' : '' }}>
                                                        Meninggal
                                                    </option>
                                                </select>
                                                @error('status_ayah')
                                                    <div class="invalid-feedback">
                                                        {{ $message }}
                                                    </div>
                                                @enderror
                                            </div>


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

                            <div class="col-md-6 ">
                                <div class="card bg-gray-100 p-2">
                                    <p class="card-text ">
                                        Status:
                                    </p>
                                    <ul class="aligned-list">
                                        <li>
                                            <span class="v2">Jumlah Anak</span>
                                            <span>:</span>
                                            <span>{{ $jumlah_anak }}</span>
                                        </li>
                                        <li>
                                            <span class="v2">Anak Meninggal</span>
                                            <span>:</span>
                                            <span>{{ $jumlah_balita_meninggal }}</span>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row no-gutters">

            <div class="col-md-6 ">
                <div class="card-body ">
                    <div class="card bg-gray-100 p-2">
                        <h5 class="card-title text-center" style="text-transform: uppercase">Status Periksa Ibu Hamil</h5>
                        <hr>
                        <nav aria-label="breadcrumb">
                            @foreach ($status_hamil as $sh)
                                <ol class="breadcrumb d-flex justify-content-between align-items-center">
                                    <li class="breadcrumb-item active">
                                        <a href="/data_pasien/{{ $sh->id }}/laporan_ibu_hamil/">
                                            Hamil Anak Ke {{ $sh->anak_ke }}
                                        </a>
                                    </li>
                                    @can('admin_is')
                                        <div>
                                            <a href="#" data-toggle="modal"
                                                data-target="#hapusDataHamil{{ $sh->id }}"
                                                class="btn btn-danger btn-sm">
                                                <span class="icon text-white">
                                                    <i class="fas fa-trash"></i>
                                                </span>
                                            </a>
                                        </div>
                                    @endcan
                                </ol>
                                <div class="modal fade" id="hapusDataHamil{{ $sh->id }}" tabindex="-1"
                                    role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                    <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <h5 class="modal-title" id="exampleModalLabel">Apakah Kamu Akan Menghapus
                                                    Data Status Hamil Ke {{ $sh->anak_ke }}
                                                </h5>
                                                <button class="close" type="button" data-dismiss="modal"
                                                    aria-label="Close">
                                                    <span aria-hidden="true">×</span>
                                                </button>
                                            </div>
                                            <div class="modal-body">Pilih "Hapus" di bawah jika Anda ingin menghapus
                                                status hamil anak ke {{ $sh->anak_ke }} dari ibu {{ $sh->nama_ibu }}

                                            </div>
                                            <div class="modal-footer">
                                                <form action="/data_hamil_ke/{{ $sh->id }}/delete" method="post"
                                                    class="d-inline">
                                                    @method('delete')
                                                    @csrf
                                                    <button class="btn btn-secondary" type="button"
                                                        data-dismiss="modal">Cancel</button>
                                                    <button class="btn btn-danger">Hapus</button>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            @endforeach

                        </nav>
                        @can('admin_is')
                            <p class="card-text ">
                                @if ($data->status_ibu == 'Meninggal')
                                    <button id="showFormBtn" class="btn btn-primary btn-sm float-right" disabled>
                                        <span class="icon text-white">
                                            <i class="fas fa-plus" id="iconToggle"></i>
                                        </span>
                                    </button>
                                @else
                                    <button id="showFormBtn" class="btn btn-primary btn-sm float-right">
                                        <span class="icon text-white">
                                            <i class="fas fa-plus" id="iconToggle"></i>
                                        </span>
                                    </button>
                                @endif
                            </p>
                        @endcan

                        <div id="formContainer" style="display: none">
                            <hr>
                            <form action ="/tambah_status_ibu_hamil/{{ $data->id }}/create" method="post">
                                @csrf
                                <div class="form-group">
                                    <label>Hamil Anak Ke</label>
                                    <input type="number" name="anak_ke"
                                        class="form-control @error('anak_ke')is-invalid @enderror"
                                        value="{{ old('anak_ke') }}">
                                    @error('anak_ke')
                                        <div class="invalid-feedback">
                                            {{ $message }}
                                        </div>
                                    @enderror
                                </div>


                                <div class="modal-footer">
                                    <button class="btn btn-primary" type="submit">Tambah</button>
                                </div>
                            </form>
                        </div>
                    </div>

                </div>
            </div>
            <div class="col-md-6 ">
                <div class="card-body ">
                    <div class="card bg-gray-100 p-2">
                        <h5 class="card-title text-center" style="text-transform: uppercase">Nama Bayi</h5>
                        <hr>
                        @foreach ($data_balita as $db)
                            <nav aria-label="breadcrumb">
                                <ol class="breadcrumb">
                                    @if ($db->status == 'Meninggal')
                                        <a aria-disabled="true">
                                            <li class="breadcrumb-item active text-dark" aria-current="page">
                                                Anak Ke {{ $db->details->anak_ke }} Telah Meninggal
                                            </li>
                                        </a>
                                    @else
                                        <a href="/data_pasien/{{ $db->id }}/laporan_data_balita">
                                            <li class="breadcrumb-item active text-primary" aria-current="page">
                                                {{ $db->nama_balita }}
                                            </li>
                                        </a>
                                    @endif

                                </ol>
                            </nav>
                        @endforeach
                    </div>

                </div>
            </div>
        </div>
    </div>



    <script>
        var formContainer = document.getElementById('formContainer');
        var showFormBtn = document.getElementById('showFormBtn');
        var formContainerv2 = document.getElementById('formContainerv2');
        var showFormBtnv2 = document.getElementById('showFormBtnv2');
        var editValue = document.getElementById('editValue');
        var formEdit = document.getElementById('formEdit');
        var iconToggle = document.getElementById('iconToggle');
        var isFormVisible = false;

        window.addEventListener('DOMContentLoaded', function() {
            var errorMessages = document.querySelectorAll('#formContainerv2 .invalid-feedback');
            if (errorMessages.length > 0) {
                formContainerv2.style.display = 'block';
                isFormVisible = true;
            }
        });

        window.addEventListener('DOMContentLoaded', function() {
            var errorMessages = document.querySelectorAll('#formContainer .invalid-feedback');
            if (errorMessages.length > 0) {
                formContainer.style.display = 'block';
                isFormVisible = true;
            }
        });

        showFormBtn.addEventListener('click', function() {
            if (!isFormVisible) {
                formContainer.style.display = 'block';
                iconToggle.className = 'fas fa-minus';
                isFormVisible = true;
            } else {
                formContainer.style.display = 'none';
                iconToggle.className = 'fas fa-plus';
                isFormVisible = false;
            }
        });
        showFormBtnv2.addEventListener('click', function() {
            if (!isFormVisible) {
                formContainerv2.style.display = 'block';
                // iconToggle.className = 'fas fa-minus';
                isFormVisible = true;
            } else {
                formContainerv2.style.display = 'none';
                // iconToggle.className = 'fas fa-plus';
                isFormVisible = false;
            }
        });
        formEdit.addEventListener('click', function() {
            if (!isFormVisible) {
                formContainerv2.style.display = 'block';
                // iconToggle.className = 'fas fa-minus';
                isFormVisible = true;
            } else {
                formContainerv2.style.display = 'none';
                // iconToggle.className = 'fas fa-plus';
                isFormVisible = false;
            }
        });


        // Menampilkan form saat terjadi validasi error




        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
