<?php

use App\Http\Controllers\International;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Admin\AuthController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\ContentSectionController;
use App\Http\Controllers\Admin\StatisticController;
use App\Http\Controllers\Admin\ImpactNumbersController;
use App\Http\Controllers\Admin\UniversityPartnersController;
use App\Http\Controllers\Admin\TestimonialsController;
use App\Http\Controllers\Admin\ContactController;
use App\Http\Controllers\Admin\EuUkManagementController;
use App\Http\Controllers\Admin\AboutManagementController;
use App\Http\Controllers\Admin\DestinationController;
use App\Http\Controllers\Admin\BlogController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\EuUkFinancialAidsController;
use App\Http\Controllers\AboutController;
use App\Http\Controllers\UniversityController;
use App\Http\Controllers\PathwayController;
use App\Http\Controllers\Admin\AdminUniversityController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', [HomeController::class, 'index'])->name('home');
Route::get('/home', [HomeController::class, 'index'])->name('home.alt');

Route::get('/about', [AboutController::class, 'index'])->name('about');

Route::get('/contact', [HomeController::class, 'contact'])->name('contact');
Route::get('/pathway', [PathwayController::class, 'index'])->name('pathway');

Route::get('/eu-uk-financial-aids', [EuUkFinancialAidsController::class, 'index'])->name('eu-uk-financial-aids');
Route::get('/international', [International::class, 'index'])->name('international');
Route::get('/universities', [UniversityController::class, 'index'])->name('universities');
Route::get('/top-universities-uk', [UniversityController::class, 'topUniversitiesUk'])->name('top-universities-uk');

// Public policy pages
Route::view('/privacy-policy', 'privacy-policy')->name('privacy.policy');
Route::view('/terms-of-service', 'terms-of-service')->name('terms.service');
Route::view('/cookie-policy', 'cookie-policy')->name('cookie.policy');

// Admin Routes
Route::prefix('admin')->name('admin.')->group(function () {
    // Guest admin routes (login)
    Route::middleware('guest:admin')->group(function () {
        Route::get('/login', [AuthController::class, 'showLoginForm'])->name('login');
        Route::post('/login', [AuthController::class, 'login']);
    });

    // Authenticated admin routes
    Route::middleware('admin.auth')->group(function () {
        Route::post('/logout', [AuthController::class, 'logout'])->name('logout');
        Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');

        // Content Sections Management
        Route::resource('content-sections', ContentSectionController::class);

        // Destinations Management
        Route::resource('destinations', DestinationController::class);

        // Statistics Management
        Route::resource('statistics', StatisticController::class);

        // Impact Numbers Management
        Route::get('impact-numbers', [ImpactNumbersController::class, 'index'])->name('impact-numbers.index');
        Route::get('impact-numbers/edit', [ImpactNumbersController::class, 'edit'])->name('impact-numbers.edit');
        Route::put('impact-numbers', [ImpactNumbersController::class, 'update'])->name('impact-numbers.update');
        Route::post('impact-numbers/add-statistic', [ImpactNumbersController::class, 'addStatistic'])->name('impact-numbers.add-statistic');
        Route::delete('impact-numbers/remove-statistic', [ImpactNumbersController::class, 'removeStatistic'])->name('impact-numbers.remove-statistic');

        // University Partners Management
        Route::get('university-partners', [UniversityPartnersController::class, 'index'])->name('university-partners.index');
        Route::get('university-partners/edit', [UniversityPartnersController::class, 'edit'])->name('university-partners.edit');
        Route::put('university-partners', [UniversityPartnersController::class, 'update'])->name('university-partners.update');
        Route::post('university-partners/add-partner', [UniversityPartnersController::class, 'addPartner'])->name('university-partners.add-partner');

        // Testimonials Management
        Route::get('testimonials', [TestimonialsController::class, 'index'])->name('testimonials.index');
        Route::get('testimonials/edit', [TestimonialsController::class, 'edit'])->name('testimonials.edit');
        Route::put('testimonials', [TestimonialsController::class, 'update'])->name('testimonials.update');
        Route::post('testimonials/add-testimonial', [TestimonialsController::class, 'addTestimonial'])->name('testimonials.add-testimonial');
        Route::delete('testimonials/remove-testimonial', [TestimonialsController::class, 'removeTestimonial'])->name('testimonials.remove-testimonial');

        // Why Select LECL Management
        Route::get('why-lecl', [\App\Http\Controllers\Admin\WhyLeclController::class, 'index'])->name('why-lecl.index');
        Route::get('why-lecl/edit', [\App\Http\Controllers\Admin\WhyLeclController::class, 'edit'])->name('why-lecl.edit');
        Route::put('why-lecl', [\App\Http\Controllers\Admin\WhyLeclController::class, 'update'])->name('why-lecl.update');
        Route::post('why-lecl/add-benefit', [\App\Http\Controllers\Admin\WhyLeclController::class, 'addBenefit'])->name('why-lecl.add-benefit');
        Route::delete('why-lecl/remove-benefit', [\App\Http\Controllers\Admin\WhyLeclController::class, 'removeBenefit'])->name('why-lecl.remove-benefit');

        // Menu Management
        Route::resource('menus', \App\Http\Controllers\Admin\MenuController::class);
        Route::post('menus/update-order', [\App\Http\Controllers\Admin\MenuController::class, 'updateOrder'])->name('menus.update-order');

        // Contact Page Management
        Route::get('contact', [ContactController::class, 'index'])->name('contact.index');
        Route::get('contact/edit', [ContactController::class, 'edit'])->name('contact.edit');
        Route::put('contact', [ContactController::class, 'update'])->name('contact.update');
        Route::post('contact/add-office', [ContactController::class, 'addOffice'])->name('contact.add-office');
        Route::delete('contact/remove-office', [ContactController::class, 'removeOffice'])->name('contact.remove-office');

        // EU/UK Financial Aids Management
        Route::get('eu-uk-management', [EuUkManagementController::class, 'index'])->name('eu-uk.index');
        Route::get('eu-uk-management/section/{sectionKey}/edit', [EuUkManagementController::class, 'editSection'])->name('eu-uk.edit-section');
        Route::put('eu-uk-management/section/{sectionKey}', [EuUkManagementController::class, 'updateSection'])->name('eu-uk.update-section');
        Route::get('eu-uk-management/preview', [EuUkManagementController::class, 'preview'])->name('eu-uk.preview');

        // About Page Management
        Route::get('about-management', [AboutManagementController::class, 'index'])->name('about.index');
        Route::get('about-management/section/{sectionKey}/edit', [AboutManagementController::class, 'editSection'])->name('about.edit-section');
        Route::put('about-management/section/{sectionKey}', [AboutManagementController::class, 'updateSection'])->name('about.update-section');
        Route::get('about-management/preview', [AboutManagementController::class, 'preview'])->name('about.preview');

        // Universities Management
        Route::resource('universities', AdminUniversityController::class);
        
        // Pathways Management
        Route::resource('pathways', \App\Http\Controllers\Admin\PathwayController::class);
        Route::post('pathways/{pathway}/toggle-status', [\App\Http\Controllers\Admin\PathwayController::class, 'toggleStatus'])->name('pathways.toggle-status');
        Route::post('pathways/update-order', [\App\Http\Controllers\Admin\PathwayController::class, 'updateOrder'])->name('pathways.update-order');
        
        // Blog Management
        Route::resource('blog', BlogController::class);
        Route::view('/privacy-policy', 'privacy-policy')->name('privacy.policy');
        Route::view('/terms-of-service', 'terms-of-service')->name('terms.service');
        Route::view('/cookie-policy', 'cookie-policy')->name('cookie.policy');
    });
});
