@extends('layouts.admin')

@section('title', 'Kelola Admin')

@section('content')
    {{-- ALERT SUKSES --}}
    @if (session('success'))
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            {{ session('success') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    @endif

    {{-- ALERT ERROR UMUM (Jika ada error selain validasi modal) --}}
    @if (session('error'))
        <div class="alert alert-danger alert-dismissible fade show" role="alert">
            {{ session('error') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    @endif
    <section class="section">
        <div class="buttons pb-3">
            <a href="#" class="btn-add-custom" data-bs-toggle="modal" data-bs-target="#create">
                <i class="bi bi-plus fs-5"></i>
                Tambah Admin
            </a>
        </div>
        <div class="card">
            <div class="card-body">
                <table class="table table-striped" id="table1">
                    <thead>
                        <tr>
                            <th style="width: 5%" class="text-center">No.</th>
                            <th style="width: 25%">Nama Lengkap</th>
                            <th style="width: 15%">Nomor WA</th>
                            <th style="width: 25%">Email</th>
                            <th style="width: 15%" class="text-center">Peran</th>
                            <th style="width: 15%" class="text-center">Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse ($admin as $a)
                            <tr>
                                <td style="width: 5%" class="text-center">{{ $loop->iteration }}</td>
                                <td style="width: 25%">{{ $a->nama }}</td>
                                <td style="width: 15%">{{ $a->no_wa }}</td>
                                <td style="width: 25%">{{ $a->email }}</td>
                                <td style="width:15%" class="text-center">
                                    <span
                                        class="badge rounded-pill px-3 py-2
        {{ $a->role == 'admin_buket' ? 'bg-success-subtle' : 'bg-warning-subtle' }}">
                                        {{ str_replace('_', ' ', $a->role) }}
                                    </span>
                                </td>
                                <td class="col-auto text-center" style="width: 15%">
                                    <a href="#" class="btn icon btn-primary btn-action" data-bs-toggle="modal"
                                        data-bs-target="#show{{ $a->id_user }}">
                                        <i class="bi bi-eye"></i>
                                    </a>

                                    <a href="#" class="btn icon btn-warning btn-action" data-bs-toggle="modal"
                                        data-bs-target="#edit{{ $a->id_user }}">
                                        <i class="bi bi-pencil"></i>
                                    </a>

                                    <a href="#" class="btn icon btn-danger btn-action" data-bs-toggle="modal"
                                        data-bs-target="#delete{{ $a->id_user }}">
                                        <i class="bi bi-trash"></i>
                                    </a>
                                </td>
                            </tr>
                            @include('admin.kelola-admin.partials.modal-show')
                            @include('admin.kelola-admin.partials.modal-edit')
                            @include('admin.kelola-admin.partials.modal-delete')
                        @empty
                            <tr>
                                <td colspan="4" class="text-center text-muted">Belum ada data admin.</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>

    </section>
    @include('admin.kelola-admin.partials.modal-create')
@endsection
