<?php

use App\Modules\Settings\Localization\Controllers\LanguageController;
use App\Modules\Settings\Localization\Controllers\LocaleController;
use App\Modules\Settings\Localization\Controllers\TranslationController;
use Illuminate\Support\Facades\Route;

Route::post('/locale/{code}', [LocaleController::class, 'switch'])
    ->whereAlphaNumeric('code')
    ->name('locale.switch');

Route::prefix('settings')->name('settings.')->group(function () {

    Route::prefix('languages')->name('languages.')->group(function () {
        Route::get('/', [LanguageController::class, 'index'])
            ->middleware('can:languages.view')->name('index');

        Route::get('/create', [LanguageController::class, 'create'])
            ->middleware('can:languages.create')->name('create');

        Route::post('/', [LanguageController::class, 'store'])
            ->middleware('can:languages.create')->name('store');

        Route::get('/{language}/edit', [LanguageController::class, 'edit'])
            ->middleware('can:languages.update,language')->name('edit');

        Route::put('/{language}', [LanguageController::class, 'update'])
            ->middleware('can:languages.update,language')->name('update');

        Route::post('/{language}/set-default', [LanguageController::class, 'setDefault'])
            ->middleware('can:languages.update,language')->name('set-default');

        Route::post('/{language}/toggle-active', [LanguageController::class, 'toggleActive'])
            ->middleware('can:languages.update,language')->name('toggle-active');

        Route::delete('/{language}', [LanguageController::class, 'destroy'])
            ->middleware('can:languages.delete,language')->name('destroy');
    });

    Route::prefix('translations')->name('translations.')->group(function () {
        Route::get('/', [TranslationController::class, 'index'])
            ->middleware('can:translations.view')->name('index');

        Route::get('/create', [TranslationController::class, 'create'])
            ->middleware('can:translations.create')->name('create');

        Route::post('/', [TranslationController::class, 'store'])
            ->middleware('can:translations.create')->name('store');

        Route::get('/{translation}/edit', [TranslationController::class, 'edit'])
            ->middleware('can:translations.update,translation')->name('edit');

        Route::put('/{translation}', [TranslationController::class, 'update'])
            ->middleware('can:translations.update,translation')->name('update');

        Route::delete('/{translation}', [TranslationController::class, 'destroy'])
            ->middleware('can:translations.delete,translation')->name('destroy');
    });
});
