@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 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">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>

                                        <div id="formContainerv2" style="display: none">
                                            <hr>
                                            <form action ="/edit_biodata/{{ $data->id }}/edit/laporan_ibu_hamil"
                                                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>
                                    @endcan
                                </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=" col-md-12 mb-4">
            <div class="card border-left-primary shadow h-100 py-2">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class=" py-3 d-flex justify-content-between align-items-center">
                                @if (
                                    $data_bayi->isNotEmpty() &&
                                        ($data_bayi->first()->status === 'Sudah Dilahirkan' || $data_bayi->first()->status === 'Meninggal'))
                                    <h6 class="m-0 font-weight-bold text-primary">Status Periksa Ibu {{ $data->nama_ibu }}
                                        => {{ $data_bayi->first()->status }}
                                    </h6>
                                @else
                                    <h6 class="m-0 font-weight-bold text-primary">Status Periksa Ibu Hamil</h6>
                                @endif
                                @cannot('admin_is')
                                    @if (
                                        $data_bayi->isNotEmpty() &&
                                            ($data_bayi->first()->status === 'Sudah Dilahirkan' || $data_bayi->first()->status === 'Meninggal'))
                                        <button id="showFormBtn" class="btn btn-dark btn-icon-split btn-sm" disabled>
                                            <span class="icon text-white-50">
                                                <i class="fas fa-plus" id="iconToggle"></i>
                                            </span>
                                            <span class="text" id="textToggle">Tambah</span>
                                        </button>
                                    @else
                                        <button id="showFormBtn" class="btn btn-primary btn-icon-split btn-sm">
                                            <span class="icon text-white-50">
                                                <i class="fas fa-plus" id="iconToggle"></i>
                                            </span>
                                            <span class="text" id="textToggle">Tambah</span>
                                        </button>
                                    @endif
                                @endcannot
                            </div>

                            <div id="formContainer" style="display: none">
                                <form action ="/status_periksa_ibu_hamil/{{ $data->id }}/create" method="post">
                                    @csrf
                                    {{-- <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') }}">
                                        @error('usia_hamil')
                                            <div class="invalid-feedback">
                                                {{ $message }}
                                            </div>
                                        @enderror
                                    </div> --}}
                                    <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') }}">
                                        @error('created_at')
                                            <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') }}">
                                        @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') }}">
                                        @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') }}">
                                        @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') == $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">Tambah</button>
                                    </div>
                                    <hr>

                                </form>
                            </div>

                            <div class="table-responsive">
                                <table id="example" class="table table-stripped table-hover">
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                            <th>Tanggal Kunjungan</th>
                                            <th>Usia Hamil</th>
                                            <th>BB</th>
                                            <th>TD</th>
                                            <th>Keluhan</th>
                                            <th>jenis Vitamin</th>
                                            @cannot('admin_is')
                                                <th>Action</th>
                                            @endcannot
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @foreach ($status_ibu_hamil as $sih)
                                            <tr>
                                                <td>{{ $loop->iteration }}</td>
                                                <td>
                                                    {{ \Carbon\Carbon::parse($sih->created_at)->format('d - F - Y') }}</td>
                                                <td>{{ $sih->usia_hamil }} Bulan</td>
                                                <td>{{ $sih->berat_badan }} Kg</td>
                                                <td>{{ $sih->tekanan_darah }}</td>
                                                <td>{{ $sih->keluhan }}</td>
                                                <td>{{ $sih->dataVitamin->nama_obat }}</td>
                                                @cannot('admin_is')
                                                    <td>
                                                        <a href="/data_pasien/laporan_ibu_hamil/{{ $sih->id }}"
                                                            class="btn btn-warning">
                                                            <span class="icon text-white">
                                                                <i class="fas fa-edit"></i>
                                                            </span>
                                                        </a>
                                                        <a href="#" data-toggle="modal"
                                                            data-target="#hapusData{{ $sih->id }}"
                                                            class="btn btn-danger">
                                                            <span class="icon text-white">
                                                                <i class="fas fa-trash"></i>
                                                            </span>
                                                        </a>
                                                    </td>
                                                @endcannot
                                            </tr>
                                            <div class="modal fade" id="hapusData{{ $sih->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 Kunjungan Tanggal
                                                                {{ \Carbon\Carbon::parse($sih->created_at)->format('d - F - Y') }}
                                                                ?
                                                            </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
                                                        </div>
                                                        <div class="modal-footer">
                                                            <form action="/status_ibu_hamil/{{ $sih->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
                                    </tbody>
                                </table>
                            </div>
                            <hr>
                            @can('admin_is')
                                @if (
                                    $data_bayi->isNotEmpty() &&
                                        ($data_bayi->first()->status === 'Sudah Dilahirkan' || $data_bayi->first()->status === 'Meninggal'))
                                    <div>
                                        <button id="showFormBtnv3" class="btn btn-dark btn-icon-split btn-sm float-right"
                                            disabled>
                                            <span class="icon text-white-50">
                                                <i class="fas fa-check" id="iconTogglev2"></i>
                                            </span>
                                            <span class="text" id="textTogglev2">Selesai</span>
                                        </button>
                                    </div>
                                @else
                                    <div>
                                        <button id="showFormBtnv3" class="btn btn-primary btn-icon-split btn-sm float-right">
                                            <span class="icon text-white-50">
                                                <i class="fas fa-check" id="iconTogglev2"></i>
                                            </span>
                                            <span class="text" id="textTogglev2">Selesai</span>
                                        </button>
                                    </div>
                                @endif
                            @endcan
                            <br>
                            <div id="formContainerv3" style="display: none">
                                <form action ="/tambah_nama_balita/{{ $data->id }}/create" method="post">
                                    @method('patch')
                                    @csrf
                                    <div class="form-group">
                                        <label for="status">Status</label>
                                        <select class="form-control @error('status') is-invalid @enderror" name="status"
                                            id="status">
                                            <option value="" {{ old('status') == '' ? 'selected' : '' }}>---
                                                Pilih ---
                                            </option>
                                            <option value="Sudah Dilahirkan"
                                                {{ old('status') == 'Sudah Dilahirkan' ? 'selected' : '' }}>Sudah
                                                Dilahirkan
                                            </option>
                                            <option value="Meninggal"
                                                {{ old('status') == 'Meninggal' ? 'selected' : '' }}>Meninggal
                                            </option>
                                        </select>
                                        @error('status')
                                            <div class="invalid-feedback">
                                                {{ $message }}
                                            </div>
                                        @enderror
                                    </div>
                                    <div class="form-group" id="nikBayiSection">
                                        <label for="status_nik_balita">Keterangan NIK Balita</label>
                                        <select class="form-control @error('status_nik_balita') is-invalid @enderror"
                                            name="status_nik_balita" id="status_nik_balita">
                                            <option value="" {{ old('status_nik_balita') == '' ? 'selected' : '' }}>
                                                --- Pilih ---
                                            </option>
                                            <option value="Memiliki NIK"
                                                {{ old('status_nik_balita') == 'Memiliki NIK' ? 'selected' : '' }}>
                                                Memiliki NIK</option>
                                            <option value="Belum Memiliki NIK"
                                                {{ old('status_nik_balita') == 'Belum Memiliki NIK' ? 'selected' : '' }}>
                                                Belum Memiliki NIK
                                            </option>
                                        </select>
                                        @error('status_nik_balita')
                                            <div class="invalid-feedback">{{ $message }}</div>
                                        @enderror
                                    </div>

                                    <div id="BayiSection" class="form-group" style="display: none;">
                                        <label>NIK Balita</label>
                                        <input type="number" name="nik_balita"
                                            class="form-control @error('nik_balita') is-invalid @enderror"
                                            value="{{ old('nik_balita') }}">
                                        @error('nik_balita')
                                            <div class="invalid-feedback">{{ $message }}</div>
                                        @enderror
                                    </div>

                                    {{-- <div class="form-group">
                                        <label>NIK Balita</label>
                                        <input type="number" name="nik_balita"
                                            class="form-control @error('nik_balita')is-invalid @enderror"
                                            value="{{ old('nik_balita') }}">
                                        @error('nik_balita')
                                            <div class="invalid-feedback">
                                                {{ $message }}
                                            </div>
                                        @enderror
                                    </div> --}}
                                    <div id="nb1" class="form-group">
                                        <label>Nama Balita</label>
                                        <input type="text" name="nama_balita"
                                            class="form-control @error('nama_balita')is-invalid @enderror"
                                            value="{{ old('nama_balita') }}">
                                        @error('nama_balita')
                                            <div class="invalid-feedback">
                                                {{ $message }}
                                            </div>
                                        @enderror
                                    </div>
                                    <div id="jk2" class="form-group">
                                        <label for="jenis_kelamin">Jenis Kelamin</label>
                                        <select class="form-control @error('jenis_kelamin') is-invalid @enderror"
                                            name="jenis_kelamin" id="jenis_kelamin">
                                            <option value="" {{ old('jenis_kelamin') == '' ? 'selected' : '' }}>
                                                ---
                                                Pilih ---
                                            </option>
                                            <option value="Laki Laki"
                                                {{ old('jenis_kelamin') == 'Laki Laki' ? 'selected' : '' }}>Laki Laki
                                            </option>
                                            <option value="Perempuan"
                                                {{ old('jenis_kelamin') == 'Perempuan' ? 'selected' : '' }}>Perempuan
                                            </option>
                                        </select>
                                        @error('jenis_kelamin')
                                            <div class="invalid-feedback">
                                                {{ $message }}
                                            </div>
                                        @enderror
                                    </div>
                                    <div id="tl3" class="form-group">
                                        <label>Tanggal Lahir</label>
                                        <input type="date" name="tanggal_lahir"
                                            class="form-control @error('tanggal_lahir')is-invalid @enderror"
                                            value="{{ old('tanggal_lahir') }}">
                                        @error('tanggal_lahir')
                                            <div class="invalid-feedback">
                                                {{ $message }}
                                            </div>
                                        @enderror
                                    </div>
                                    <div id="jl4" class="form-group">
                                        <label>Jam Lahir</label>
                                        <input type="time" name="jam_lahir"
                                            class="form-control @error('jam_lahir')is-invalid @enderror"
                                            value="{{ old('jam_lahir') }}">
                                        @error('jam_lahir')
                                            <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>
        </div>

    </div>
    <script>
        var formContainer = document.getElementById('formContainer');
        var showFormBtn = document.getElementById('showFormBtn');
        var formContainerv2 = document.getElementById('formContainerv2');
        var showFormBtnv2 = document.getElementById('showFormBtnv2');
        var formContainerv3 = document.getElementById('formContainerv3');
        var showFormBtnv3 = document.getElementById('showFormBtnv3');
        var iconToggle = document.getElementById('iconToggle');
        var iconTogglev2 = document.getElementById('iconTogglev2');
        var textToggle = document.getElementById('textToggle');
        var textTogglev2 = document.getElementById('textTogglev2');

        var isFormVisible = false;

        document.addEventListener("DOMContentLoaded", function() {
            var statusSelect = document.getElementById("status");
            var BayiSection = document.getElementById("BayiSection");
            var statusSelectBayi = document.getElementById("status_nik_balita");
            var nbSection = document.getElementById("nb1");
            var jkSection = document.getElementById("jk2");
            var tlSection = document.getElementById("tl3");
            var jlSection = document.getElementById("jl4");
            var nkSection = document.getElementById("nikBayiSection");


            function updateVisibility() {
                console.log("Status Balita:", statusSelect.value);
                console.log("Status NIK Balita:", statusSelectBayi.value);

                if (statusSelect.value === "Sudah Dilahirkan") {
                    nbSection.style.display = "block";
                    jkSection.style.display = "block";
                    tlSection.style.display = "block";
                    jlSection.style.display = "block";
                    nkSection.style.display = "block";

                } else {
                    nbSection.style.display = "none";
                    jkSection.style.display = "none";
                    tlSection.style.display = "none";
                    jlSection.style.display = "none";
                    nkSection.style.display = "none";
                }

                if (statusSelect.value === "Sudah Dilahirkan" && statusSelectBayi.value === "Memiliki NIK") {
                    BayiSection.style.display = "block";
                } else {
                    BayiSection.style.display = "none";
                }
            }

            // Membuat pengecekan awal saat halaman dimuat
            updateVisibility();

            // Menambahkan event listener ke dropdown
            statusSelect.addEventListener("change", updateVisibility);
            statusSelectBayi.addEventListener("change", updateVisibility);

            // Menghapus class is-invalid saat input mendapat fokus
            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';
                    }
                });
            });

            var formCheckInputs = document.querySelectorAll('.form-check-input');
            formCheckInputs.forEach(function(formCheckInput) {
                formCheckInput.addEventListener('change', function() {
                    var errorFeedback = this.parentNode.parentNode.querySelector(
                        '.invalid-feedback');
                    if (errorFeedback) {
                        errorFeedback.style.display = 'none';
                    }
                });
            });
        });

        if (showFormBtnv2) {
            showFormBtnv2.addEventListener('click', function() {
                if (!isFormVisible) {
                    formContainerv2.style.display = 'block';
                    iconTogglev2.className = 'fas fa-times';
                    textTogglev2.textContent = 'Tutup';
                    isFormVisible = true;
                } else {
                    formContainerv2.style.display = 'none';
                    iconTogglev2.className = 'fas fa-check';
                    textTogglev2.textContent = 'Selesai';
                    isFormVisible = false;
                }
            });
        }

        if (showFormBtnv3) {
            showFormBtnv3.addEventListener('click', function() {
                if (!isFormVisible) {
                    formContainerv3.style.display = 'block';
                    iconTogglev2.className = 'fas fa-times';
                    textTogglev2.textContent = 'Tutup';
                    isFormVisible = true;
                } else {
                    formContainerv3.style.display = 'none';
                    iconTogglev2.className = 'fas fa-check';
                    textTogglev2.textContent = 'Selesai';
                    isFormVisible = false;
                }
            });
        }

        if (showFormBtn) {
            showFormBtn.addEventListener('click', function() {
                if (!isFormVisible) {
                    formContainer.style.display = 'block';
                    iconToggle.className = 'fas fa-minus';
                    textToggle.textContent = 'Tutup';
                    isFormVisible = true;
                } else {
                    formContainer.style.display = 'none';
                    iconToggle.className = 'fas fa-plus';
                    textToggle.textContent = 'Tambah';
                    isFormVisible = false;
                }
            });
        }


        window.addEventListener('DOMContentLoaded', function() {
            var errorMessages = document.querySelectorAll('#formContainer .invalid-feedback');
            if (errorMessages.length > 0) {
                formContainer.style.display = 'block';
                isFormVisible = true;
            }
        });
        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('#formContainerv3 .invalid-feedback');
            if (errorMessages.length > 0) {
                formContainerv3.style.display = 'block';
                isFormVisible = true;
            }
        });
    </script>
@endsection
