<?php

use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ValidationMessageController;
use App\Http\Controllers\Frontend\Auth\LoginController;
use Stancl\Tenancy\Middleware\InitializeTenancyByDomain;
use Stancl\Tenancy\Middleware\PreventAccessFromCentralDomains;

Auth::routes(['login' => false]);

Route::middleware(['demo.mode'])->group(function () {
    if (!in_array(url('/'), config('tenancy.central_domains')) && config('app.mood') === 'Saas' && isModuleActive('Saas')) {

        $middleware = [];

        if (!config('app.single_db')) {
            $middleware = [
                'web',
                InitializeTenancyByDomain::class,
                PreventAccessFromCentralDomains::class
            ];
        } else {
            $middleware = [
                'web',
                'check.company.subdomain'
            ];
        }
    } else {
        $middleware = ['web'];
    }

    Route::middleware($middleware)->group(
        function () {
            Route::get('sign-in', [LoginController::class, 'adminLogin'])->name('adminLogin')->middleware('xss');

            Auth::routes();
            //admin routes here
            include_route_files(__DIR__ . '/admin/');

            //frontend routes here
            include_route_files(__DIR__ . '/frontend/');

            //====================Validation Message Generate===============================
            Route::get('validation-message-generate', function () {
                return view('validation-message-generate');
            })->name('test')->middleware('xss');

            Route::POST('validation-message-generate', [ValidationMessageController::class, 'messageGenerate'])->name('message_generate')->middleware('xss');
        }
    );
});
