@extends('admin.layouts.app')

@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <div class="d-flex justify-content-between align-items-center mb-4">
                <h1>Study Destinations Management</h1>
                <a href="{{ route('admin.destinations.create') }}" class="btn btn-primary">
                    <i class="fas fa-plus"></i> Add New Destination
                </a>
            </div>

            @if(session('success'))
                <div class="alert alert-success alert-dismissible fade show" role="alert">
                    {{ session('success') }}
                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                </div>
            @endif

            <div class="card">
                <div class="card-body">
                    @if($destinations->count() > 0)
                        <div class="table-responsive">
                            <table class="table table-striped">
                                <thead>
                                    <tr>
                                        <th>Sort Order</th>
                                        <th>Flag</th>
                                        <th>Name</th>
                                        <th>Universities</th>
                                        <th>Status</th>
                                        <th>Actions</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach($destinations as $destination)
                                        <tr>
                                            <td>{{ $destination->sort_order }}</td>
                                            <td>
                                                <span style="font-size: 1.5rem;">{{ $destination->flag }}</span>
                                            </td>
                                            <td>
                                                <strong>{{ $destination->name }}</strong>
                                                <br>
                                                <small class="text-muted">{{ Str::limit($destination->description, 50) }}</small>
                                            </td>
                                            <td>
                                                <span class="badge bg-info">{{ $destination->universities_count }} Universities</span>
                                            </td>
                                            <td>
                                                @if($destination->is_active)
                                                    <span class="badge bg-success">Active</span>
                                                @else
                                                    <span class="badge bg-secondary">Inactive</span>
                                                @endif
                                            </td>
                                            <td>
                                                <div class="btn-group" role="group">
                                                    <a href="{{ route('admin.destinations.show', $destination) }}" 
                                                       class="btn btn-sm btn-outline-info" title="View">
                                                        <i class="fas fa-eye"></i>
                                                    </a>
                                                    <a href="{{ route('admin.destinations.edit', $destination) }}" 
                                                       class="btn btn-sm btn-outline-primary" title="Edit">
                                                        <i class="fas fa-edit"></i>
                                                    </a>
                                                    <form action="{{ route('admin.destinations.destroy', $destination) }}" 
                                                          method="POST" class="d-inline" 
                                                          onsubmit="return confirm('Are you sure you want to delete this destination?')">
                                                        @csrf
                                                        @method('DELETE')
                                                        <button type="submit" class="btn btn-sm btn-outline-danger" title="Delete">
                                                            <i class="fas fa-trash"></i>
                                                        </button>
                                                    </form>
                                                </div>
                                            </td>
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    @else
                        <div class="text-center py-5">
                            <i class="fas fa-globe fa-3x text-muted mb-3"></i>
                            <h4>No destinations found</h4>
                            <p class="text-muted">Start by adding your first study destination.</p>
                            <a href="{{ route('admin.destinations.create') }}" class="btn btn-primary">
                                <i class="fas fa-plus"></i> Add First Destination
                            </a>
                        </div>
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@push('styles')
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
@endpush