<?php

use App\Http\Controllers\ContactController;
use App\Http\Controllers\DownloadController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\PageController;
use App\Http\Controllers\RegistrationController;
use App\Http\Controllers\SubmissionController;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Mail;

// Test email route (remove after testing)
Route::get('/test-email/{email?}', function ($email = 'teflinuin@gmail.com') {
    try {
        Mail::raw('Test email from TEFLIN Conference - ' . now(), function ($message) use ($email) {
            $message->to($email)
                    ->subject('Test Email from TEFLIN');
        });
        return 'Email sent to ' . $email . '! Check your inbox.';
    } catch (\Exception $e) {
        return 'Email failed: ' . $e->getMessage();
    }
});

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

// Dynamic Page Route (for CMS pages)
Route::get('/page/{slug}', [PageController::class, 'show'])->name('page.show');

// About The Conference
Route::get('/about/{slug?}', [PageController::class, 'about'])->name('about');

// Keynote & Plenary Speakers
Route::get('/speakers/{slug?}', [PageController::class, 'speakers'])->name('speakers');

// Call For Papers
Route::get('/call-for-papers/{slug?}', [PageController::class, 'callForPapers'])->name('call-for-papers');

// Registration & Fees
Route::get('/registration/{slug?}', [PageController::class, 'registration'])->name('registration');

// Venue & Travel
Route::get('/venue/{slug?}', [PageController::class, 'venue'])->name('venue');

// Documentation
Route::get('/documentation', [PageController::class, 'documentation'])->name('documentation');

// Publication
Route::get('/publication', [PageController::class, 'publication'])->name('publication');

// Resources & Contact
Route::get('/resources/{slug?}', [PageController::class, 'resources'])->name('resources');

// News
Route::get('/news', [PageController::class, 'news'])->name('news');
Route::get('/news/{slug}', [PageController::class, 'newsDetail'])->name('news.detail');

// Submission
Route::get('/submission-portal', [SubmissionController::class, 'portal'])->name('submission.portal');
Route::get('/submit-abstract', [SubmissionController::class, 'abstractForm'])->name('submission.abstract');
Route::post('/submit-abstract', [SubmissionController::class, 'submitAbstract'])->name('submission.abstract.store');
Route::get('/submit-full-paper', [SubmissionController::class, 'fullPaperForm'])->name('submission.full-paper');
Route::post('/submit-full-paper', [SubmissionController::class, 'submitFullPaper'])->name('submission.full-paper.store');
Route::get('/check-submission', [SubmissionController::class, 'checkStatus'])->name('submission.check');
Route::post('/check-submission', [SubmissionController::class, 'getStatus'])->name('submission.check.status');
Route::get('/submission-success', [SubmissionController::class, 'success'])->name('submission.success');
Route::get('/submission/{submission}/download/{type}', [SubmissionController::class, 'downloadFile'])->name('submission.download')->where('type', 'abstract|paper');

// Registration Form
Route::get('/register', [RegistrationController::class, 'form'])->name('registration.form');
Route::post('/register', [RegistrationController::class, 'store'])->name('registration.store');
Route::get('/registration-success', [RegistrationController::class, 'success'])->name('registration.success');
Route::get('/check-registration', [RegistrationController::class, 'checkStatus'])->name('registration.check');
Route::post('/check-registration', [RegistrationController::class, 'getStatus'])->name('registration.check.status');

// Contact
Route::get('/contact', [ContactController::class, 'form'])->name('contact');
Route::post('/contact', [ContactController::class, 'store'])->name('contact.store');

// Downloads
Route::get('/download/{id}', [DownloadController::class, 'download'])->name('download');

// Legal Pages
Route::get('/privacy-policy', [PageController::class, 'privacyPolicy'])->name('privacy-policy');
Route::get('/terms-of-use', [PageController::class, 'termsOfUse'])->name('terms-of-use');

