<?php
/**
 * Created by PhpStorm.
 * User: radko
 * Date: 13.11.18
 * Time: 8:11
 */

use Illuminate\Support\Facades\Route;
use Seka\Portal\Modul\Vzdelavanie\Http\Controllers\Backend\Kniznica\KategoriaController;
use Seka\Portal\Modul\Vzdelavanie\Http\Controllers\Backend\Kniznica\KniznicaController;
use Seka\Portal\Modul\Vzdelavanie\Http\Controllers\Backend\Kniznica\SekciaController;
use Seka\Portal\Modul\Vzdelavanie\Http\Controllers\Backend\Kniznica\UcebnicaController;

if ($domain = config('vzdelavanie.subdomena')) {
    $domain = sprintf(
        '%s.%s',
        $domain,
        config('app.domain'),
    );
}

$path = config('vzdelavanie.cesta');

Route::domain($domain)
    ->prefix($path)
    ->middleware(['web', 'auth', 'permission:vzdelavanie'])
    ->name('vzdelavanie.')
    ->group(function () {
        Route::prefix('sprava')
            ->name('sprava.')
            ->group(function () {
                Route::prefix('kniznica')
                    ->name('kniznica.')
                    ->group(function () {
                        Route::get('/', [KniznicaController::class, 'index'])
                            ->name('index');

                        Route::prefix('kategorie')
                            ->name('kategoria.')
                            ->group(function () {
                                Route::get('/', [KategoriaController::class, 'index'])
                                    ->name('index');

                                Route::get('/nova', [KategoriaController::class, 'create'])
                                    ->name('create');

                                Route::post('/nova', [KategoriaController::class, 'store'])
                                    ->name('store');

                                Route::prefix('{vzdKnzncKategoriaId}')
                                    ->group(function () {
                                        Route::get('/upravit', [KategoriaController::class, 'edit'])
                                            ->name('edit');

                                        Route::put('/upravit', [KategoriaController::class, 'update'])
                                            ->name('update');

                                        Route::delete('/odstranit', [KategoriaController::class, 'destroy'])
                                            ->name('destroy');

                                        Route::prefix('/ucebny-material')
                                            ->name('ucebnice.')
                                            ->group(function () {
                                                Route::get('/', [UcebnicaController::class, 'index'])
                                                    ->name('index');

                                                Route::post('/', [UcebnicaController::class, 'index'])
                                                    ->name('filter');

                                                Route::get('/novy', [UcebnicaController::class, 'create'])
                                                    ->name('create');

                                                Route::post('/novy', [UcebnicaController::class, 'store'])
                                                    ->name('store');

                                                Route::prefix('{vzdKnzncUcbnMtrlId}')
                                                    ->group(function () {
                                                        Route::get('/upravit', [UcebnicaController::class, 'edit'])
                                                            ->name('edit');

                                                        Route::put('/upravit', [UcebnicaController::class, 'update'])
                                                            ->name('update');

                                                        Route::delete(
                                                            '/odstranit',
                                                            [UcebnicaController::class, 'destroy'],
                                                        )
                                                            ->name('destroy');

                                                        Route::prefix('/sekcie')
                                                            ->name('sekcia.')
                                                            ->group(function () {
                                                                Route::get('/', [SekciaController::class, 'index'])
                                                                    ->name('index');

                                                                Route::get('/nova', [SekciaController::class, 'create'])
                                                                    ->name('create');

                                                                Route::post('/nova', [SekciaController::class, 'store'])
                                                                    ->name('store');

                                                                Route::prefix('{vzdKnzncSekciaId}')
                                                                    ->group(function () {
                                                                        Route::get(
                                                                            '/upravit',
                                                                            [SekciaController::class, 'edit'],
                                                                        )
                                                                            ->name('edit');

                                                                        Route::put(
                                                                            '/upravit',
                                                                            [SekciaController::class, 'update'],
                                                                        )
                                                                            ->name('update');

                                                                        Route::delete(
                                                                            '/odstranit',
                                                                            [SekciaController::class, 'destroy'],
                                                                        )
                                                                            ->name('destroy');
                                                                    });
                                                            });
                                                    });
                                            });
                                    });
                            });
                    });
            });
    });
