<?php

declare(strict_types=1);

use App\Livewire\Admin\Auth\Login as AdminLogin;
use App\Livewire\Admin\Blog\Categories\Index as BlogCategoriesIndex;
use App\Livewire\Admin\Blog\Posts\Form as BlogPostsForm;
use App\Livewire\Admin\Blog\Posts\Index as BlogPostsIndex;
use App\Livewire\Admin\Blog\PostReviews\Manage as BlogPostReviewsManage;
use App\Livewire\Admin\Blog\Tags\Index as BlogTagsIndex;
use App\Livewire\Admin\Communications\SendEmail;
use App\Livewire\Admin\Dashboard;
use App\Livewire\Admin\EmailTemplates\Index as EmailTemplatesIndex;
use App\Livewire\Admin\HomepageBanners\Index as HomepageBannersIndex;
use App\Livewire\Admin\Logs\Index as LogsIndex;
use App\Livewire\Admin\Notifications\Index as NotificationsIndex;
use App\Livewire\Admin\PaymentMethods\Edit as PaymentMethodsEdit;
use App\Livewire\Admin\PaymentMethods\Index as PaymentMethodsIndex;
use App\Livewire\Admin\Profile\Edit as ProfileEdit;
use App\Livewire\Admin\ReviewedWebsites\CommunityReviewsManage as TrustDirectoryCommunityReviewsManage;
use App\Livewire\Admin\ReviewedWebsites\ReviewsModerate as TrustDirectoryReviewsModerate;
use App\Livewire\Admin\ReviewedWebsites\WebsiteForm as TrustDirectoryWebsiteForm;
use App\Livewire\Admin\ReviewedWebsites\WebsitesIndex as TrustDirectoryWebsitesIndex;
use App\Livewire\Admin\Settings\Edit as SettingsEdit;
use App\Livewire\Admin\Settings\Index as SettingsIndex;
use App\Livewire\Admin\Settings\SeoSettings as SettingsSeo;
use App\Livewire\Admin\Settings\SocialAuth as SettingsSocialAuth;
use App\Livewire\Admin\SupportTickets\Index as SupportTicketsIndex;
use App\Livewire\Admin\TrustChecks\Overview as TrustChecksOverview;
use App\Livewire\Admin\Users\Edit as UsersEdit;
use App\Livewire\Admin\Users\Index as UsersIndex;
use App\Livewire\Admin\Users\Show as UsersShow;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Admin Routes
|--------------------------------------------------------------------------
*/

Route::middleware('guest')->prefix('admin')->name('admin.')->group(function (): void {
    Route::get('/login', AdminLogin::class)->name('login');
});

Route::middleware('auth')->prefix('admin')->name('admin.')->group(function (): void {
    Route::post('/logout', function () {
        auth()->logout();
        request()->session()->invalidate();
        request()->session()->regenerateToken();

        return redirect()->route('admin.login');
    })->name('logout');
});

Route::middleware(['auth', 'role:admin'])->prefix('admin')->name('admin.')->group(function (): void {
    Route::get('/dashboard', Dashboard::class)->name('dashboard');

    Route::get('/users', UsersIndex::class)->name('users.index');
    Route::get('/users/{user}', UsersShow::class)->name('users.show');
    Route::get('/users/{user}/edit', UsersEdit::class)->name('users.edit');

    Route::get('/communications/send-email', SendEmail::class)->name('communications.send-email');

    Route::get('/support-tickets', SupportTicketsIndex::class)->name('support-tickets.index');

    Route::get('/blog', function () {
        return redirect()->route('admin.blog.posts.index');
    })->name('blog.index');
    Route::get('/blog/post-reviews', BlogPostReviewsManage::class)->name('blog.post-reviews.index');
    Route::get('/blog/posts', BlogPostsIndex::class)->name('blog.posts.index');
    Route::get('/blog/posts/create', BlogPostsForm::class)->name('blog.posts.create');
    Route::get('/blog/posts/{post}/edit', BlogPostsForm::class)
        ->whereNumber('post')
        ->name('blog.posts.edit');
    Route::get('/blog/categories', BlogCategoriesIndex::class)->name('blog.categories.index');
    Route::get('/blog/tags', BlogTagsIndex::class)->name('blog.tags.index');

    Route::get('/trust-checks', TrustChecksOverview::class)->name('trust-checks.index');

    Route::get('/reviewed-websites', TrustDirectoryWebsitesIndex::class)->name('reviewed-websites.index');
    Route::get('/reviewed-websites/community-reviews', TrustDirectoryCommunityReviewsManage::class)->name('reviewed-websites.community-reviews');
    Route::get('/reviewed-websites/moderate-reviews', TrustDirectoryReviewsModerate::class)->name('reviewed-websites.reviews.moderate');
    Route::get('/reviewed-websites/create', TrustDirectoryWebsiteForm::class)->name('reviewed-websites.create');
    Route::get('/reviewed-websites/{reviewedWebsite}/edit', TrustDirectoryWebsiteForm::class)
        ->whereNumber('reviewedWebsite')
        ->name('reviewed-websites.edit');

    Route::get('/homepage-banners', HomepageBannersIndex::class)->name('homepage-banners.index');

    Route::get('/email-templates', EmailTemplatesIndex::class)->name('email-templates.index');

    Route::get('/notifications', NotificationsIndex::class)->name('notifications.index');

    Route::get('/payment-methods', PaymentMethodsIndex::class)->name('payment-methods.index');
    Route::get('/payment-methods/{paymentMethod}/edit', PaymentMethodsEdit::class)->name('payment-methods.edit');

    Route::get('/settings', SettingsIndex::class)->name('settings.index');
    Route::get('/settings/seo', SettingsSeo::class)->name('settings.seo');
    Route::get('/settings/social-auth', SettingsSocialAuth::class)->name('settings.social-auth');
    Route::get('/settings/{setting}/edit', SettingsEdit::class)->name('settings.edit');

    Route::get('/profile', ProfileEdit::class)->name('profile.edit');

    Route::get('/audit-logs', LogsIndex::class)->name('audit-logs.index');
    Route::get('/logs', LogsIndex::class)->name('logs.index');
});
