<?php

use App\Http\Controllers\Admin\ArchiveAdminController;
use App\Http\Controllers\Admin\ConfirmacionController;
use App\Http\Controllers\Admin\EmailAdminController;
use App\Http\Controllers\Admin\GraciasAdminController;
use App\Http\Controllers\Admin\HomeAdminController;
use App\Http\Controllers\Admin\HomeController as AdminHomeController;
use App\Http\Controllers\Admin\NewsletterController;
use App\Http\Controllers\Admin\PageController;
use App\Http\Controllers\Admin\PartyControllers;
use App\Http\Controllers\Admin\PostController;
use App\Http\Controllers\Admin\WelcomeController;
use App\Http\Controllers\EmailController;
use App\Http\Controllers\GraciasController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\SitemapController;
use App\Models\Archive;
use App\Models\Confirmacion;
use App\Models\Email;
use App\Models\Gracias;
use App\Models\Page;
use App\Models\Party;
use App\Models\Post;
use Illuminate\Support\Facades\Route;

Route::get('/', HomeController::class);

Route::get('/confirmacion/{email}', function($email){
    
    $email = Email::where('emailencryption', $email)->first();
    $email->aprobado=1;
    $email->save();

    $pages = Confirmacion::all();
    return view('confirmacion', compact('pages'));

})->name('confirmacion');

Route::get('/debaja/{email}', function($email){
    
    $email = Email::where('emailencryption', $email)->first();
    $email->debaja=0;
    $email->save();
    return view('adios');

});

Route::get('sitemap.xml', [SitemapController::class, 'index']);


Route::get('/gracias', function(){
    $gracias = Party::all();
    $paths = Archive::all(); 
    return view('gracias', compact('gracias', 'paths'));
})->name('gracias');

Route::middleware([
    'auth:sanctum',
    config('jetstream.auth_session'),
    'verified',
])->group(function () {
    Route::get('/dashboard', function () {
        return view('dashboard');
    })->name('dashboard');
});

Route::get('/admin', function () {
    $emails = Email::all();
    return view('admin.dashboard', compact('emails'));
})->name('admin.dashboard')->middleware('auth');

Route::resource('/admin/pages', PageController::class);
Route::resource('/admin/posts', PostController::class);
Route::resource('/admin/emails', EmailAdminController::class);
Route::resource('/admin/newsletter', NewsletterController::class);
Route::resource('/admin/confirmacion', ConfirmacionController::class);
Route::resource('/admin/home', HomeAdminController::class);
Route::resource('/admin/party', PartyControllers::class);
Route::resource('/admin/welcome', WelcomeController::class);
Route::resource('/admin/archive', ArchiveAdminController::class);



Route::get('/blog', function(){

    $pages = Page::all();
    $posts = Post::all();

    return view('blog', compact('pages', 'posts'));
});

Route::resource('/email', EmailController::class);


Route::get('/{page}/{post?}', function(Page $page, Post $post = null){

    if ($post) {
        return view('post', compact('post'));
    }
    return view('page', compact('page'));
    
});



