@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">Data Bidan</h6>
            <a href="/user/bidan/tambah" 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-body">
            <div class="table-responsive">
                <table id="example" class="table table-stripped table-hover">
                    <thead>
                        <tr>
                            <th class="text-center">#</th>
                            <th class="text-center">Nama Lengkap</th>
                            <th class="text-center">Username</th>
                            <th class="text-center">Password</th>
                            <th class="text-center">Action</th>
                        </tr>
                    </thead>
                    <tbody class="text-center">
                        @foreach ($dataUser->where('is_admin', '0') as $du)
                            <tr>
                                <td>{{ $loop->iteration }}</td>
                                <td>{{ $du->nama_lengkap }}</td>
                                <td>{{ $du->username }}</td>
                                <td>{{ $du->password }}</td>

                                <td>
                                    <a href="/edit_bidan/edit/{{ $du->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{{ $du->id }}"
                                        class="btn btn-danger">
                                        <span class="icon text-white">
                                            <i class="fas fa-trash"></i>
                                        </span>
                                    </a>
                                </td>
                            </tr>
                            <div class="modal fade" id="hapusData{{ $du->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
                                                Bidan {{ $du->nama_lengkap }}?
                                            </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 data bidan
                                            {{ $du->nama_lengkap }}
                                        </div>
                                        <div class="modal-footer">
                                            <form action="/hapus/{{ $du->id }}/bidan" 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>
        </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
