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

use Illuminate\Support\Facades\Route;
use Seka\Vzdelavanie\Http\Controllers\Frontend\Kniznica\KategoriaController;
use Seka\Vzdelavanie\Http\Controllers\Frontend\Kniznica\KniznicaController;
use Seka\Vzdelavanie\Http\Controllers\Frontend\Kniznica\SekciaController;
use Seka\Vzdelavanie\Http\Controllers\Frontend\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|vzdelavanie_kniznica|vzdelavanie_kniznica.zobrazit'])
    ->name('vzdelavanie.')
    ->group(function () {
        Route::prefix('kniznica')
            ->name('kniznica.')
            ->group(function () {
                Route::get('/', [KniznicaController::class, 'index'])
                    ->name('index');

                Route::prefix('ucebny-material/{vzdKnzncUcbnMtrlId}')
                    ->name('ucebnica.')
                    ->group(function () {
                        Route::get('/', [UcebnicaController::class, 'show'])
                            ->name('show');

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

                                Route::get('/{vzdKnzncSekciaId}', [SekciaController::class, 'show'])
                                    ->name('show');
                            });
                    });

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

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