@include('includes.header')

<div class="page-wrapper">
    <div class="page-content">

        <!-- Page Header + Controls -->
        <div class="card border-0 shadow-sm mb-3">
            <div class="card-body d-flex flex-wrap justify-content-between align-items-center gap-2">

                <!-- Left: Title + Info -->
                <div>
                    <h5 class="mb-0 text-uppercase">Attendance List</h5>

                </div>

                <!-- Right: Actions -->
                <div class="d-flex align-items-center gap-2">

                    <!-- Search -->
                    <input type="text" class="form-control form-control-sm" style="width: 220px;"
                        placeholder="🔍 Search store...">

                    <!-- Add Button -->


                </div>

            </div>


            <!-- Table Card -->
            <div class="card border-0 shadow-sm">
                <div class="card-body p-0">

                    <div class="table-responsive">
                        <table class="table table-hover align-middle mb-0">

                            <!-- Table Head -->
                            <thead class="bg-light">
                                <tr>
                                    <th class="ps-4">S.NO</th>

                                    <th>Employee Name</th>
                                    <th>Email</th>
                                    <th>Phone</th>
                                    <th>Sign In</th>
                                    <th>Sign Out</th>
                                    <th>Date</th>
                                    <th class="text-center">Actions</th>
                                </tr>
                            </thead>

                            <!-- Table Body -->
                            <tbody>
                                @foreach ($attendance as $row)
                                    <tr>
                                        <td>{{ $loop->iteration }}</td>



                                        <td>
                                            {{ $row->employee->first_name ?? '' }}
                                            {{ $row->employee->last_name ?? '' }}
                                        </td>

                                        <td>{{ $row->employee->email ?? '-' }}</td>

                                        <td>{{ $row->employee->phone ?? '-' }}</td>

                                        <td>
                                            {{ $row->sign_in ? \Carbon\Carbon::parse($row->sign_in)->format('h:i A') : '-' }}
                                        </td>

                                        <td>
                                            @if ($row->sign_out)
                                                {{ \Carbon\Carbon::parse($row->sign_out)->format('h:i A') }}
                                            @else
                                                <span class="badge bg-warning text-dark">Active (In Store)</span>
                                            @endif
                                        </td>

                                        <td>{{ $row->date }}</td>

                                        <td class="text-center">

                                            <form action="{{ route('store.attendance.destroy', $row->id) }}"
                                                method="POST" onsubmit="return confirm('Are you sure?')">
                                                @csrf
                                                @method('DELETE')
                                                <div class="d-flex justify-content-center gap-2"></div>
                                                <button class="btn btn-sm btn-outline-danger">
                                                    <i class="bx bx-trash"></i>
                                                </button>
                    </div>
                    </form>

                    </td>
                    </tr>
                    @endforeach
                    </tbody>
                    </table>
                </div>

            </div>

            <!-- Pagination -->
            <div class="card-footer bg-white d-flex justify-content-between align-items-center">

                <small class="text-muted">
                    Showing <b>1</b> to <b>2</b> of <b>10</b> entries
                </small>

                <ul class="pagination pagination-sm mb-0">
                    <li class="page-item disabled"><a class="page-link">Previous</a></li>
                    <li class="page-item active"><a class="page-link">1</a></li>
                    <li class="page-item"><a class="page-link">2</a></li>
                    <li class="page-item"><a class="page-link">3</a></li>
                    <li class="page-item"><a class="page-link">Next</a></li>
                </ul>

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

</div>
</div>
<script>
    function deleteRecord(id) {
        if (confirm('Are you sure?')) {
            fetch(`/attendance/${id}`, {
                method: 'DELETE',
                headers: {
                    'X-CSRF-TOKEN': '{{ csrf_token() }}'
                }
            }).then(res => location.reload());
        }
    }
</script>
@include('includes.footer')
