@extends('admin.layout')

@section('title', 'Support Tickets')

@section('content')
<div class="data-table">
  <table>
    <thead>
      <tr>
        <th>User</th>
        <th>Subject</th>
        <th>Priority</th>
        <th>Status</th>
        <th>Created</th>
        <th>Actions</th>
      </tr>
    </thead>
    <tbody>
      @forelse ($tickets as $ticket)
        <tr>
          <td>{{ $ticket->user->name ?? 'N/A' }}</td>
          <td>{{ $ticket->subject }}</td>
          <td>
            <span class="badge 
              @if($ticket->priority === 'urgent') badge-danger
              @elseif($ticket->priority === 'high') badge-warning
              @else badge-info
              @endif">
              {{ ucfirst($ticket->priority) }}
            </span>
          </td>
          <td>
            <span class="badge 
              @if($ticket->status === 'open') badge-warning
              @elseif($ticket->status === 'resolved') badge-success
              @else badge-info
              @endif">
              {{ ucfirst(str_replace('_', ' ', $ticket->status)) }}
            </span>
          </td>
          <td>{{ $ticket->created_at->format('M d, Y') }}</td>
          <td>
            <form method="POST" action="{{ route('admin.support.update', $ticket) }}">
              @csrf
              @method('PUT')
              <select name="status" class="btn btn-sm" style="background: #334155; color: #f8fafc; margin-right: 4px;">
                <option value="open" {{ $ticket->status === 'open' ? 'selected' : '' }}>Open</option>
                <option value="in_progress" {{ $ticket->status === 'in_progress' ? 'selected' : '' }}>In Progress</option>
                <option value="resolved" {{ $ticket->status === 'resolved' ? 'selected' : '' }}>Resolved</option>
                <option value="closed" {{ $ticket->status === 'closed' ? 'selected' : '' }}>Closed</option>
              </select>
              <button type="submit" class="btn btn-primary btn-sm">Save</button>
            </form>
          </td>
        </tr>
      @empty
        <tr>
          <td colspan="6" class="empty-state">No tickets found.</td>
        </tr>
      @endforelse
    </tbody>
  </table>
</div>

<div style="margin-top: 24px;">
  {{ $tickets->links() }}
</div>
@endsection
