@extends('admin.layouts.app')

@section('title', 'EU/UK Financial Aids Management')

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="d-flex justify-content-between align-items-center mb-4">
                <h1 class="h3">EU/UK Financial Aids Management</h1>
                <div class="btn-group">
                    <a href="{{ route('eu-uk-financial-aids') }}" class="btn btn-outline-primary" target="_blank">
                        <i class="bi bi-eye"></i> Preview Page
                    </a>
                    <a href="{{ route('admin.content-sections.index') }}" class="btn btn-secondary">
                        <i class="bi bi-arrow-left"></i> All Content Sections
                    </a>
                </div>
            </div>
        </div>
    </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

    <!-- Statistics Cards -->
    <div class="row mb-4">
        <div class="col-md-3">
            <div class="card bg-primary text-white">
                <div class="card-body">
                    <div class="d-flex justify-content-between">
                        <div>
                            <h4 class="mb-0">{{ $sectionStats['total_sections'] }}</h4>
                            <p class="mb-0">Total Sections</p>
                        </div>
                        <div class="align-self-center">
                            <i class="bi bi-file-text" style="font-size: 2rem;"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card bg-success text-white">
                <div class="card-body">
                    <div class="d-flex justify-content-between">
                        <div>
                            <h4 class="mb-0">{{ $sectionStats['active_sections'] }}</h4>
                            <p class="mb-0">Active Sections</p>
                        </div>
                        <div class="align-self-center">
                            <i class="bi bi-check-circle" style="font-size: 2rem;"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card bg-warning text-white">
                <div class="card-body">
                    <div class="d-flex justify-content-between">
                        <div>
                            <h4 class="mb-0">{{ $sectionStats['inactive_sections'] }}</h4>
                            <p class="mb-0">Inactive Sections</p>
                        </div>
                        <div class="align-self-center">
                            <i class="bi bi-x-circle" style="font-size: 2rem;"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card bg-info text-white">
                <div class="card-body">
                    <div class="d-flex justify-content-between">
                        <div>
                            <h6 class="mb-0">Last Updated</h6>
                            <p class="mb-0">{{ $sectionStats['last_updated'] ? $sectionStats['last_updated']->format('M d, Y') : 'Never' }}</p>
                        </div>
                        <div class="align-self-center">
                            <i class="bi bi-clock" style="font-size: 2rem;"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- EU/UK Sections Management -->
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">EU/UK Financial Aids Content Sections</h5>
                    <small class="text-muted">Manage all content sections specific to the EU/UK Financial Aids page</small>
                </div>
                <div class="card-body">
                    @if($euUkSections->count() > 0)
                        <div class="table-responsive">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>Section</th>
                                        <th>Title</th>
                                        <th>Content Preview</th>
                                        <th>Status</th>
                                        <th>Last Updated</th>
                                        <th>Actions</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach($euUkSections as $section)
                                        <tr>
                                            <td>
                                                <span class="badge bg-secondary">{{ $section->section_key }}</span>
                                            </td>
                                            <td>
                                                <strong>{{ $section->title }}</strong>
                                            </td>
                                            <td>
                                                <div class="text-truncate" style="max-width: 200px;">
                                                    {{ Str::limit(strip_tags($section->content), 50) }}
                                                </div>
                                            </td>
                                            <td>
                                                @if($section->is_active)
                                                    <span class="badge bg-success">Active</span>
                                                @else
                                                    <span class="badge bg-secondary">Inactive</span>
                                                @endif
                                            </td>
                                            <td>
                                                <small class="text-muted">
                                                    {{ $section->updated_at->format('M d, Y H:i') }}
                                                </small>
                                            </td>
                                            <td>
                                                <div class="btn-group btn-group-sm" role="group">
                                                    <a href="{{ route('admin.content-sections.show', $section) }}" 
                                                       class="btn btn-outline-info" title="View">
                                                        <i class="bi bi-eye"></i>
                                                    </a>
                                                    <a href="{{ route('admin.content-sections.edit', $section) }}" 
                                                       class="btn btn-outline-primary" title="Edit">
                                                        <i class="bi bi-pencil"></i>
                                                    </a>
                                                </div>
                                            </td>
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    @else
                        <div class="text-center py-5">
                            <i class="bi bi-file-text text-muted" style="font-size: 4rem;"></i>
                            <h4 class="text-muted mt-3">No EU/UK Sections Found</h4>
                            <p class="text-muted">It looks like the EU/UK content sections haven't been seeded yet.</p>
                            <a href="{{ route('admin.content-sections.create') }}" class="btn btn-primary mt-3">
                                <i class="bi bi-plus"></i> Create EU/UK Section
                            </a>
                        </div>
                    @endif
                </div>
            </div>
        </div>
    </div>

    <!-- Quick Actions -->
    <div class="row mt-4">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">Quick Actions</h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-4">
                            <div class="d-grid">
                                <a href="{{ route('admin.content-sections.create') }}" class="btn btn-outline-primary">
                                    <i class="bi bi-plus-circle"></i> Add New Section
                                </a>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="d-grid">
                                <a href="{{ route('eu-uk-financial-aids') }}" class="btn btn-outline-success" target="_blank">
                                    <i class="bi bi-eye"></i> Preview Live Page
                                </a>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="d-grid">
                                <a href="{{ route('admin.content-sections.index') }}" class="btn btn-outline-secondary">
                                    <i class="bi bi-list"></i> All Content Sections
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection