@extends('layouts.app')
@section('title', 'Data Pengguna')
@section('subtitle', 'Setting')
@section('content')
    <div class="row">
        <div class="col-lg-12 d-flex align-items-stretch">
            <div class="card w-100">
                <div class="card-body p-4">
                    <div class="d-flex align-items-stretch">
                        <h5 class="card-title fw-semibold mb-4">Data Pengguna</h5>
                        <div class="d-inline ms-auto">
                            <a href="{{ route('users.create') }}" class="btn btn-sm btn-success">
                                <i class="ti ti-user-plus"></i>&nbsp; Tambah
                            </a>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-hover table-bordered text-nowrap mb-0 align-middle">
                            <thead class="text-dark fs-4">
                                <tr>
                                    <th class="border-bottom-0" width="70px">
                                        <h6 class="fw-semibold mb-0 text-center">No.</h6>
                                    </th>
                                    <th class="border-bottom-0">
                                        <h6 class="fw-semibold mb-0">Name</h6>
                                    </th>
                                    <th class="border-bottom-0">
                                        <h6 class="fw-semibold mb-0">Terakhir Diupdate</h6>
                                    </th>
                                    <th class="border-bottom-0" width="100px">
                                        <h6 class="fw-semibold mb-0 text-center">Action</h6>
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                @forelse ($users as $user)
                                    <tr>
                                        <td class="border-bottom-0">
                                            <h6 class="fw-normal mb-0 text-center">
                                                {{ ($users->currentPage() - 1) * $users->perPage() + $loop->index + 1 }}.
                                            </h6>
                                        </td>
                                        <td class="border-bottom-0">
                                            <h6 class="fw-semibold mb-1">{{ $user->name }}</h6>
                                            <span class="fw-normal">{{ $user->email }}</span>
                                        </td>
                                        <td class="border-bottom-0">
                                            <h6 class="fw-normal mb-0 fs-4">{{ $user->updated_at }}</h6>
                                        </td>
                                        <td class="border-bottom-0">
                                            <div class="d-flex align-items-center gap-2">
                                                <a href="{{ route('users.edit', $user->id) }}"
                                                    class="btn btn-sm btn-primary"><i class="ti ti-edit"></i> Ubah</a>
                                                {{-- <form onsubmit="return confirm('Apakah Anda Yakin ?');" action="{{ route('users.update', $user->id) }}" method="POST">
                                                    @csrf
                                                    @method('DELETE')
                                                    <button type="submit" class="btn btn-sm btn-danger">Hapus</button>
                                                </form>  --}}
                                            </div>
                                        </td>
                                    </tr>
                                @empty
                                    <div class="alert alert-danger">
                                        Data Pengguna belum Tersedia.
                                    </div>
                                @endforelse
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    @if (Session::has('users-message'))
        <script>
            Swal.fire({
                text: "{{ Session::get('users-message')['msg'] }}",
                icon: "{{ Session::get('users-message')['type'] }}",
                timer: 2500
            });
        </script>
    @endif
@stop
