<?php

use App\Http\Controllers\VerifyController;
use App\Livewire\Activities\Index as ActivitiesIndex;
use App\Livewire\Admin\Translations\Index as TranslationIndex;
use App\Livewire\Agent\Index as AgentIndex;
use App\Livewire\Auth\ForgotPassword;
use App\Livewire\Auth\Login;
use App\Livewire\Auth\Register;
use App\Livewire\Auth\ResetPassword;
use App\Livewire\Auth\VerifyNotice;
use App\Livewire\Automation\Index as AutomationIndex;
use App\Livewire\Calendar\Index as CalendarIndex;
use App\Livewire\Contacts\Index as ContactsIndex;
use App\Livewire\Integration\Index as IntegrationIndex;
use App\Http\Controllers\Integration\GoogleCalendarController;
use App\Http\Controllers\Integration\OutlookCalendarController;
use App\Http\Controllers\Webhooks\GoogleCalendarWebhookController;
use App\Livewire\Plans\Index as PlansIndex;
use App\Livewire\Settings\Index as SettingsIndex;
use Illuminate\Support\Facades\Route;



Route::get('/mail-preview', function () {
    return view('emails.auth.verify', [
        'user' => 'Max Mustermann',
        'code' => '123456',
        'url' => 'https://example.com/verify' // 🔥 hinzufügen
    ]);
});

Route::middleware(['auth.custom'])->group(function () {
    // intentionally empty — kept for middleware reference
});

Route::middleware('guest.custom')->group(function () {
    Route::get('/login', Login::class)->name('login');
    Route::get('/register', Register::class)->name('register');

    Route::get('/password/reset', ForgotPassword::class)->name('password.request');
    Route::get('/password/reset/{token}', ResetPassword::class)->name('password.reset');

    Route::get('/verify/{verification}', [VerifyController::class, 'verify'])
        ->name('verify.user')
        ->middleware('signed');

    Route::get('/verify-notice/{user}', VerifyNotice::class)->name('verify.notice');
});


// Admin-Bereich: Support+ kann Dashboard & User sehen
Route::middleware(['user', 'role:support'])->prefix('admin')->name('admin.')->group(function () {
    Route::get('/', \App\Livewire\Admin\Dashboard::class)->name('dashboard');
    Route::get('/users', \App\Livewire\Admin\Users\Index::class)->name('users.index');
    Route::get('/users/{user}', \App\Livewire\Admin\Users\Detail::class)->name('users.detail');
    Route::get('/users/{user}/calendar', \App\Livewire\Admin\Users\Calendar::class)->name('users.calendar');
});

// Admin-Bereich: Admin+ kann Pläne, Affiliates, Übersetzungen verwalten
Route::middleware(['user', 'role:admin'])->prefix('admin')->name('admin.')->group(function () {
    Route::get('/plans', \App\Livewire\Admin\Plans\Index::class)->name('plans.index');
    Route::get('/affiliates', \App\Livewire\Admin\Affiliates\Index::class)->name('affiliates.index');
    Route::get('/translations', TranslationIndex::class)->name('translations.index');
    Route::get('/versions', \App\Livewire\Admin\Versions::class)->name('versions.index');
});

Route::middleware('user')->group(function () {

    Route::get('/', App\Livewire\Dashboard\Index::class)->name('dashboard.index');
    Route::get('/calendar', \App\Livewire\Calendar\WeekCanvas::class)->name('calendar.index');
    Route::get('/agent', AgentIndex::class)->name('agent.index');
    Route::get('/agent/logs', \App\Livewire\Agent\Logs::class)->name('agent.logs');
    Route::get('/activities', ActivitiesIndex::class)->name('activities.index');
    Route::get('/notes', \App\Livewire\Notes\Index::class)->name('notes.index');
    Route::get('/tasks', \App\Livewire\Tasks\Index::class)->name('tasks.index');
    Route::get('/contacts', ContactsIndex::class)->name('contacts.index');
    Route::get('/plans', PlansIndex::class)->name('plans.index');
    Route::get('/subscription', \App\Livewire\Subscription\Index::class)->name('subscription.index');
    Route::get('/invoices', \App\Livewire\Invoices\Index::class)->name('invoices.index');
    Route::get('/checkout/success', \App\Livewire\Checkout\Success::class)->name('checkout.success');
    Route::get('/checkout/{planId}/{billing?}', \App\Livewire\Checkout\Index::class)->name('checkout.index');
    Route::get('/integrations', IntegrationIndex::class)->name('integrations.index');
    Route::get('/automations', AutomationIndex::class)->name('automations.index');
    Route::get('/settings', SettingsIndex::class)->name('settings.index');
    Route::get('/settings/affiliate', fn() => redirect()->route('settings.index', ['tab' => 'affiliate']))->name('settings.affiliate');

    Route::post('/logout', function () {
        auth()->logout();
        return redirect('/');

    })->name('logout');
});
