@extends('layouts.admin')
@section('title','Manajemen Pengguna')
@section('content')
<div class="card">
  <div class="card-header d-flex justify-content-between align-items-center">
    <span>Pengguna Internal</span>
    <a href="{{ route('admin.users.create') }}" class="btn btn-primary btn-sm"><i class="fas fa-plus me-1"></i>Tambah User</a>
  </div>
  <div class="table-responsive">
    <table class="table table-hover mb-0">
      <thead><tr><th>Nama</th><th>Email</th><th>Role</th><th>Divisi</th><th>Status</th><th>2FA</th><th></th></tr></thead>
      <tbody>
      @forelse($users as $u)
      <tr>
        <td class="fw-semibold small">{{ $u->name }}</td>
        <td class="small text-muted">{{ $u->email }}</td>
        <td><span class="badge {{ ['admin'=>'bg-danger','cs'=>'bg-primary','technician'=>'bg-success'][$u->role]??'bg-secondary' }}">{{ strtoupper($u->role) }}</span></td>
        <td><span class="badge bg-light text-dark border">{{ $u->division }}</span></td>
        <td>@if($u->is_active)<span class="badge badge-ok">Aktif</span>@else<span class="badge bg-secondary">Nonaktif</span>@endif</td>
        <td>@if($u->two_factor_enabled)<span class="badge bg-success"><i class="fas fa-shield-halved"></i> ON</span>@else<span class="text-muted small">—</span>@endif</td>
        <td class="d-flex gap-1">
          <a href="{{ route('admin.users.edit',$u) }}" class="btn btn-sm btn-outline-secondary"><i class="fas fa-edit"></i></a>
          @if($u->id !== auth()->id() && auth()->user()->role === 'admin')
          <form action="{{ route('admin.users.destroy',$u) }}" method="POST" onsubmit="return confirm('Hapus user?')">@csrf @method('DELETE')<button class="btn btn-sm btn-outline-danger"><i class="fas fa-trash"></i></button></form>
          @endif
        </td>
      </tr>
      @empty<tr><td colspan="7" class="text-center text-muted py-4">Tidak ada user</td></tr>
      @endforelse
      </tbody>
    </table>
  </div>
  <div class="card-footer">{{ $users->links() }}</div>
</div>
@endsection
