@extends('layouts.app')

@section('title','Manajemen User')

@section('content')

<div class="container-fluid">

    {{-- Header --}}
    <div class="d-flex justify-content-between align-items-center mb-4">

        <div>

            <h3 class="font-weight-bold mb-1">
                Manajemen User
            </h3>

            <p class="text-muted mb-0">
                Kelola seluruh akun pengguna sistem PRESGURU.
            </p>

        </div>

        <a href="{{ route('user.create') }}"
           class="btn btn-primary btn-modern">

            <i class="fas fa-user-plus mr-1"></i>

            Tambah User

        </a>

    </div>

    {{-- Statistik --}}
    <div class="row mb-4">

        <div class="col-md-4">

            <div class="small-card">

                <div>

                    <small>Total User</small>

                    <h2>{{ $users->count() }}</h2>

                </div>

                <div class="small-icon bg-primary">

                    <i class="fas fa-users"></i>

                </div>

            </div>

        </div>

    </div>

    {{-- Table --}}
    <div class="card card-modern">

        <div class="card-header bg-white border-0">

            <h5 class="mb-0">

                <i class="fas fa-users-cog text-primary mr-2"></i>

                Data User

            </h5>

        </div>

        <div class="card-body">

            <div class="table-responsive">

                <table class="table table-modern table-hover datatable">

                    <thead>

                        <tr>

                            <th>Nama User</th>
                            <th>Email</th>
                            <th>Role</th>
                            <th width="150" class="text-center">
                                Aksi
                            </th>

                        </tr>

                    </thead>

                    <tbody>

                        @foreach($users as $u)

                        <tr>

                            <td>

                                <div class="d-flex align-items-center">

                                    <img
                                        src="https://ui-avatars.com/api/?name={{ urlencode($u->name) }}&background=2563eb&color=fff"
                                        class="rounded-circle mr-2"
                                        width="42">

                                    <div>

                                        <strong>

                                            {{ $u->name }}

                                        </strong>

                                    </div>

                                </div>

                            </td>

                            <td>

                                <i class="fas fa-envelope text-muted mr-1"></i>

                                {{ $u->email }}

                            </td>

                            <td>

                                @if($u->role=='admin')

                                    <span class="badge badge-danger px-3 py-2">

                                        Administrator

                                    </span>

                                @elseif($u->role=='guru')

                                    <span class="badge badge-success px-3 py-2">

                                        Guru

                                    </span>

                                @elseif($u->role=='staff')

                                    <span class="badge badge-info px-3 py-2">

                                        Staff

                                    </span>

                                @else

                                    <span class="badge badge-secondary">

                                        {{ ucfirst($u->role) }}

                                    </span>

                                @endif

                            </td>

                            <td class="text-center">

                                <a
                                    href="{{ route('user.edit',$u->id) }}"
                                    class="btn btn-warning btn-sm rounded-circle"
                                    title="Edit">

                                    <i class="fas fa-pencil-alt"></i>

                                </a>

                                <form
                                    action="{{ route('user.destroy',$u->id) }}"
                                    method="POST"
                                    class="d-inline">

                                    @csrf
                                    @method('DELETE')

                                    <button
                                        class="btn btn-danger btn-sm rounded-circle"
                                        onclick="return confirm('Yakin ingin menghapus user ini?')">

                                        <i class="fas fa-trash"></i>

                                    </button>

                                </form>

                            </td>

                        </tr>

                        @endforeach

                    </tbody>

                </table>

            </div>

        </div>

    </div>

</div>

@endsection