@extends('layouts.admin')
@section('title','Activity Log')
@section('content')
<ul class="nav nav-tabs mb-3">
  <li class="nav-item"><a class="nav-link" href="{{ route('admin.settings.index') }}">Perusahaan</a></li>
  <li class="nav-item"><a class="nav-link" href="{{ route('admin.settings.sla') }}">SLA Config</a></li>
  <li class="nav-item"><a class="nav-link active" href="{{ route('admin.settings.activity') }}">Activity Log</a></li>
</ul>
<div class="card mb-3"><div class="card-body py-2">
  <form class="row g-2" method="GET">
    <div class="col-md-3"><select name="module" class="form-select form-select-sm"><option value="">Semua Modul</option>@foreach(['ticket','client','invoice','visit','workorder','project','auth','user'] as $m)<option value="{{ $m }}" {{ request('module')===$m?'selected':'' }}>{{ strtoupper($m) }}</option>@endforeach</select></div>
    <div class="col-md-3"><select name="user_id" class="form-select form-select-sm"><option value="">Semua User</option>@foreach($users as $u)<option value="{{ $u->id }}" {{ request('user_id')==$u->id?'selected':'' }}>{{ $u->name }}</option>@endforeach</select></div>
    <div class="col-auto"><button type="submit" class="btn btn-primary btn-sm"><i class="fas fa-search"></i></button><a href="{{ route('admin.settings.activity') }}" class="btn btn-secondary btn-sm ms-1"><i class="fas fa-xmark"></i></a></div>
  </form>
</div></div>
<div class="card">
  <div class="table-responsive">
    <table class="table table-hover mb-0" style="font-size:12.5px">
      <thead><tr><th>Waktu</th><th>User</th><th>Modul</th><th>Aksi</th><th>Deskripsi</th><th>IP</th></tr></thead>
      <tbody>
      @forelse($logs as $log)
      <tr>
        <td class="text-muted" style="white-space:nowrap">{{ $log->created_at->format('d/m/Y H:i:s') }}</td>
        <td>{{ $log->user?->name ?? '<span class="text-muted">System</span>' }}</td>
        <td><span class="badge bg-light text-dark border">{{ strtoupper($log->module) }}</span></td>
        <td><span class="badge bg-secondary small">{{ $log->action }}</span></td>
        <td class="text-muted">{{ $log->description }}</td>
        <td class="text-muted small">{{ $log->ip_address }}</td>
      </tr>
      @empty<tr><td colspan="6" class="text-center text-muted py-4">Tidak ada log</td></tr>
      @endforelse
      </tbody>
    </table>
  </div>
  <div class="card-footer">{{ $logs->links() }}</div>
</div>
@endsection
