@extends('layouts.master')
@section('content')
<style>
    input[type="checkbox"]{
        height: 22px; width: 22px;
    }
</style>


    <div class="container-xxl flex-grow-1 container-p-y">

        @if (isset($faces))
            <div class="row" style="display: flow-root">
                <h5 class="card-title">All Faces</h5>
            </div>
        @endif
        <div class="card container" style="display: grid;height: 100%;">
            <div class="table-responsive text-nowrap mt-4" style="display: inline-table !important;">
                <table class="display table " style="height: 100%;" id="myDataTable">
                    <thead>
                        <tr class="text-nowrap">
                            <th>#</th>
                            <th>Image</th>
                            <th>Name</th>
                            <th>Email</th>
                            <th>Phone No</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>

                        @if ($faces)
                            @foreach ($faces as $index => $list)
                                <tr>
                                    <th scope="row">{{ ++$index }}</th>
                                    <td>

                                    <img src="data:image/png;base64,{{ $list['face_image'] }}" alt="Face" style="height: 70px; width: 70px;" />

                                    </td>
                                    <td>{{ $list['attendee_name'] ?? "" }}</td>
                                    <td>{{ $list['attendee_email'] ?? "" }}</td>
                                    <td>{{ $list['attendee_phone_number'] ?? "" }}</td>


                                    <td>
                                        <div class="dropdown">
                                            <a role="button" data-bs-toggle="dropdown" aria-expanded="false">
                                                <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20"
                                                    fill="#ffffff" viewBox="0 0 256 256">
                                                    <path
                                                        d="M156,128a28,28,0,1,1-28-28A28,28,0,0,1,156,128ZM128,76a28,28,0,1,0-28-28A28,28,0,0,0,128,76Zm0,104a28,28,0,1,0,28,28A28,28,0,0,0,128,180Z">
                                                    </path>
                                                </svg>
                                            </a>
                                            <ul class="dropdown-menu">


                                                <li>
                                                    <a class="dropdown-item" href="{{ route('faces.face_detail', $list['_id']) }}">
                                                        <i style="color: red;" class="menu-icon tf-icons bx bx-trash"></i>
                                                        View More Details</a>
                                                </li>

                                                <li>
                                                    <a class="dropdown-item" href="javacsript::void(0)"
                                                        onclick="deleteCamera('{{ $list['_id'] }}')">
                                                        <i style="color: red;" class="menu-icon tf-icons bx bx-trash"></i>
                                                        Delete</a>
                                                </li>

                                            </ul>
                                        </div>
                                    </td>
                                </tr>
                            @endforeach
                        @endif
                    </tbody>
                </table>
            </div>
        </div>
        <div class="row" style=" text-align: center; display: block; margin-top: 100px; margin-bottom: 65px; ">
            {{-- <a href="" class="btn btn-secondary" style="width: 150px;margin-right: 50px;">Back</a> --}}
            {{-- <a href="" class="btn btn-primary" style="width: 150px;">Next</a> --}}
        </div>


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


    <script>
        function deleteCamera(id) {
            Swal.fire({
                title: "Are you sure?",
                text: "You won't be able to revert this!",
                icon: "warning",
                showCancelButton: true,
                confirmButtonColor: "#3085d6",
                cancelButtonColor: "#d33",
                confirmButtonText: "Yes, delete it!"
            }).then((result) => {
                if (result.isConfirmed) {
                    window.location.href = "{{ url('face_delete/') }}/" + id;
                }
            });
        }


        $(document).ready(function() {
            $('#myDataTable').DataTable({
                searching: true,
                ordering: true,
                info: false,
                lengthChange: false, // This line hides the entries dropdown
                pageLength: 10, // Optional: Set default number of entries per page
                "order": [], // Disable initial sorting
                "columnDefs": [{
                        "orderable": true,
                        "targets": "_all"
                    }, // Make all columns orderable
                    {
                        "type": "string",
                        "targets": "_all"
                    } // Treat all column data as strings for sorting
                ],
                language: {
                    paginate: {
                        previous: "<i class='fas fa-angle-left'></i>", // Icon for previous button
                        next: "<i class='fas fa-angle-right'></i>" // Icon for next button
                    }
                }
            });

            // $("#searchCamera").on('change', function() {
            //     $('#myDataTable').DataTable().column(1).search(
            //         $(this).val(),
            //         false, // regex
            //         true // smart search
            //     ).draw();
            // });

            // $("#searchRegion").on('change', function() {
            //     $('#myDataTable').DataTable().column(2).search(
            //         $(this).val(),
            //         false, // regex
            //         true // smart search
            //     ).draw();
            // });

            // $("#searchUrl").on('keyup', function() {
            //     $('#myDataTable').DataTable().column(3).search(
            //         $(this).val(),
            //         false, // regex
            //         true // smart search
            //     ).draw();
            // });
        });
    </script>

<!-- testing -->
@endSection
