<?php

declare(strict_types=1);

use App\Http\Controllers\Admin\ImpersonateController;
use App\Livewire\Blog\HomePage as BlogHomePage;
use App\Livewire\Blog\IndexPage as BlogIndexPage;
use App\Livewire\Blog\ShowPage as BlogShowPage;
use App\Livewire\PublicPage;
use App\Livewire\TrustSites\WebsiteShow as TrustWebsiteShow;
use App\Http\Controllers\RobotsController;
use App\Http\Controllers\SitemapController;
use App\Livewire\TrustSites\WebsitesIndex as TrustWebsitesIndex;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Route;

Route::get('/robots.txt', RobotsController::class)->name('robots');
Route::get('/sitemap.xml', SitemapController::class)->name('sitemap');

// Blog homepage (editorial hub)
Route::get('/', BlogHomePage::class)->name('home');

// Content pages
Route::get('/pricing', PublicPage::class)->name('pricing');
Route::get('/blog', BlogIndexPage::class)->name('blog');
Route::get('/blog/category/{categorySlug}', BlogIndexPage::class)->name('blog.category');
Route::get('/blog/tag/{tagSlug}', BlogIndexPage::class)->name('blog.tag');
Route::get('/websites', TrustWebsitesIndex::class)->name('websites.index');
Route::get('/websites/{slug}', TrustWebsiteShow::class)->name('websites.show');
Route::get('/blog/{slug}', BlogShowPage::class)->name('blog.show');
Route::get('/resources', PublicPage::class)->name('resources');
Route::get('/about', PublicPage::class)->name('about');
Route::get('/contact', PublicPage::class)->name('contact');

// Legal & help: permanent redirects to Google policy and support pages
Route::permanentRedirect('/licensing', 'https://www.google.com/permissions/')->name('licensing');
Route::permanentRedirect('/faq', 'https://support.google.com/')->name('faq');
Route::permanentRedirect('/guides', 'https://about.google/products/')->name('guides');
Route::permanentRedirect('/terms-of-service', 'https://policies.google.com/terms')->name('terms');
Route::permanentRedirect('/privacy-policy', 'https://policies.google.com/privacy')->name('privacy');

Route::get('/refund-policy', PublicPage::class)->name('refund-policy');

// Dark mode setting (available to all)
Route::post('/dark-mode', function () {
    $mode = request()->json('mode', 'system');
    session(['dark_mode' => $mode]);

    return response()->json(['success' => true]);
})->name('dark-mode.set');

// Impersonation routes (admin only)
Route::middleware('auth')->group(function () {
    Route::get('/impersonate/take/{id}', [ImpersonateController::class, 'take'])->middleware('role:admin')->name('impersonate');
    Route::get('/impersonate/leave', [ImpersonateController::class, 'leave'])->name('impersonate.leave');
});

Route::get('/cron', function () {
    Artisan::call('schedule:run');

    return response()->json(['success' => true, 'message' => 'Success']);
})->name('cron');
