<?php

use Illuminate\Support\Facades\Route;
use Livewire\Volt\Volt;

// Gemeinsame Web-Routes für alle Pages)
// Jede Landing-Page hat das gleiche Gerüst, aber unterschiedliches Styling

// Hauptseite - lädt automatisch das richtige Theme basierend auf der Domain
Route::get('/', function () {
    $theme = config('app.theme', 'b2in');

    // Use theme-specific view if it exists (e.g., web.b2a, web.stileigentum)
    // The view name for b2in theme is 'web.b2in' and not 'web.home'
    if ($theme === 'b2in') {
        return view('web.home');
    }
    if (view()->exists('web.'.$theme)) {
        return view('web.'.$theme);
    }

    // Fallback to the default home view
    return view('web.home');
})->name('home');

// Willkommensseite
Route::get('/welcome', function () {
    return view('web.welcome');
})->name('welcome');

// Weitere gemeinsame Webseiten hier...
Route::get('/about', function () {
    return view('web.about');
})->name('about');
Route::get('/ecosystem', function () {
    return view('web.ecosystem');
})->name('ecosystem');
Route::get('/partner', function () {
    return view('web.partner');
})->name('partner');
Route::get('/magazin', function () {
    return view('web.magazin');
})->name('magazin');
Route::get('/magazin/{id}', function ($id) {
    return view('web.magazin-detail', compact('id'));
})->name('magazin.detail');
Route::get('/contact', function () {
    return view('web.contact');
})->name('contact');

Route::get('/service', function () {
    return view('web.service');
})->name('service');

Route::get('/portfolio', function () {
    return view('web.portfolio');
})->name('portfolio');

Route::get('/faq', function () {
    return view('web.faq');
})->name('faq');

// Theme Demo Route
Route::get('/theme-demo', function () {
    return view('web.theme-demo');
})->name('theme-demo');

// Pfad-basierte Theme-Routen für lokale Entwicklung wurden entfernt
// Die Themensauswahl wird nun über den ThemeServiceProvider gesteuert (Domain oder ?theme=... GET-Parameter)

Route::get('/partner/invitation/expired/{token}', function (string $token) {
    $invitation = \App\Models\PartnerInvitation::with('role')->where('token', $token)->firstOrFail();

    return view('partner.invitation-expired', compact('invitation'));
})->name('partner.invitation.expired');

Route::get('/partner/invitation/used/{token}', function (string $token) {
    $invitation = \App\Models\PartnerInvitation::with('role')->where('token', $token)->firstOrFail();

    return view('partner.invitation-used', compact('invitation'));
})->name('partner.invitation.used');

Volt::route('/partner/invitation/{token}', 'partner.invitation-accept')
    ->name('partner.invitation.accept');

Volt::route('/partner/create-account', 'partner.create-account')
    ->name('partner.create.account');

// Öffentliche Registrierung per QR-/Code (Landing, code-check)
Volt::route('/reg/{role}', 'reg.landing')
    ->name('registration.landing');

Volt::route('/registration/thank-you', 'reg.thank-you')
    ->name('registration.thank-you');

// Partner Setup Wizard & Daten
Route::middleware('auth')->group(function () {
    Volt::route('/partner/setup', 'partner.setup-wizard')
        ->name('partner.setup.wizard');
});

// Authentifizierungs-Routen werden in domains.php eingebunden
// require __DIR__ . '/auth.php';
