@extends('Dashboard.layouts.main')

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

@section('breadcrumb')
<li class="breadcrumb-item"><a href="{{ route('dashboard') }}">Dashboard</a></li>
<li class="breadcrumb-item active">Daftar Admin</li>
@endsection

@section('page-title', 'Pengelolaan Admin')

@section('content')
<div class="row">
    <div class="col-12">
        <div class="card-box">
            <div class="row mb-3">
                <div class="col-12">
                    <a href="{{ route('admin.admins.create') }}" class="btn btn-primary waves-effect waves-light">
                        <i class="fe-plus"></i> Tambah Admin Baru
                    </a>
                </div>
            </div>

            @if(session('success'))
            <div class="alert alert-success alert-dismissible fade show" role="alert">
                {{ session('success') }}
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            @endif

            @if(session('error'))
            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                {{ session('error') }}
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            @endif

            <div class="table-responsive">
                <table id="datatable" class="table table-centered table-striped dt-responsive nowrap w-100">
                    <thead>
                        <tr>
                            <th>No</th>
                            <th>Nama</th>
                            <th>Email</th>
                            <th>Jenis Kelamin</th>
                            <th>Tanggal Dibuat</th>
                            <th>Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($admins as $index => $admin)
                        <tr>
                            <td>{{ $index + 1 }}</td>
                            <td>{{ $admin->name }}</td>
                            <td>{{ $admin->email }}</td>
                            <td>{{ $admin->gender }}</td>
                            <td>{{ $admin->created_at->format('d/m/Y H:i') }}</td>
                            <td>
                                <a href="{{ route('admin.admins.edit', $admin->id) }}" class="btn btn-sm btn-warning">
                                    <i class="fe-edit"></i> Edit
                                </a>
                                
                                @if(auth()->id() !== $admin->id)
                                <button type="button" class="btn btn-sm btn-danger" onclick="confirmDelete('{{ route('admin.admins.destroy', $admin->id) }}')">
                                    <i class="fe-trash-2"></i> Hapus
                                </button>
                                @endif
                            </td>
                        </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<!-- Sertakan Modal Konfirmasi Hapus -->
@include('layouts.delete-modal')
@endsection

@section('scripts')
<script>
    $(document).ready(function() {
        $('#datatable-buttons').DataTable({
            dom: 'Bfrtip',
            buttons: [
                'copy', 'csv', 'excel', 'pdf', 'print'
            ]
        });
    });
</script>
@endsection 