@extends('capture.layoutv6')


@section('content')
<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-body">
                <h5 class="card-title">All Hospital</h5>

                <!-- Search Input -->
                <div class="row mb-3">
                    <div class="col-md-6">
                        <div class="input-group">
                            <span class="input-group-text"><i class="fas fa-search"></i></span>
                            <input type="text" class="form-control" id="searchInput" placeholder="ค้นหาโรงพยาบาล..." onkeyup="searchTable()">
                        </div>
                    </div>
                </div>

                <table class="table table-bordered" id="hospitalTable">
                    <thead>
                        <tr>
                            <th>Hospital</th>
                            <th>code</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach ($tb_department as $department)
                            <tr>
                                <td>{{ @$department['department_name'] }}</td>
                                <td>{{ @$department['department_code'] }}</td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<script>
function searchTable() {
    var input, filter, table, tr, td, i, txtValue;
    input = document.getElementById("searchInput");
    filter = input.value.toUpperCase();
    table = document.getElementById("hospitalTable");
    tr = table.getElementsByTagName("tr");

    for (i = 1; i < tr.length; i++) {
        td = tr[i].getElementsByTagName("td");
        var found = false;

        for (var j = 0; j < td.length; j++) {
            if (td[j]) {
                txtValue = td[j].textContent || td[j].innerText;
                if (txtValue.toUpperCase().indexOf(filter) > -1) {
                    found = true;
                    break;
                }
            }
        }

        if (found) {
            tr[i].style.display = "";
        } else {
            tr[i].style.display = "none";
        }
    }
}
</script>
@endsection