<?php

use Illuminate\Support\Facades\Route;

Route::group(['prefix' => localeFromRequest()], function(){
    // Home
    Route::get('/', 'FrontendController@home')->name('home');

    // Movie
    Route::get('movie-popular', 'FrontendController@moviePopular')->name('movie.popular');
    Route::get('movie-now-playing', 'FrontendController@movieNowPlaying')->name('movie.now.playing');
    Route::get('movie-top-rated', 'FrontendController@movieTopRated')->name('movie.top.rated');
    Route::get('movie-upcoming', 'FrontendController@movieUpcoming')->name('movie.upcoming');
    Route::prefix('movie')->group(function () {
        Route::get('/', 'FrontendController@movieNowPlaying');
        Route::get('/{id}/{slug?}', 'FrontendController@singleMovie')->name('movie.single');
    });

    // Tv Shows
    Route::get('tv-popular', 'FrontendController@tvPopular')->name('tv.popular');
    Route::get('tv-top-rated', 'FrontendController@tvTopRated')->name('tv.top.rated');
    Route::get('tv-airing-to-day', 'FrontendController@tvAiringToday')->name('tv.airing.to.day');
    Route::get('tv-on-the-air', 'FrontendController@tvOnTheAir')->name('tv.on.the.air');
    Route::prefix('tv')->group(function () {
        Route::get('/', 'FrontendController@tvAiringToday')->name('tv');
        Route::get('/{id}-{season}-{episode}/{slug?}', 'FrontendController@singleTVSeasonEpisode')->where([
                'id' => '[0-9]+',
                'season' => '[0-9]+',
                'episode' => '[0-9]+'
            ])->name('tv.single.season.episode');
        Route::get('/{id}-{season}/{slug?}', 'FrontendController@singleTVSeason')->where([
            'id' => '[0-9]+',
            'season' => '[0-9]+'
            ])->name('tv.single.season');
        Route::get('/{id}/{slug?}', 'FrontendController@singleTv')->where('id', '[tt0-9]+')->name('tv.single');
    });

    // People
    Route::prefix('person')->group( function () {
        Route::get('/{id}', 'FrontendController@people')->where(['id' => '[0-9]+'])->name('people.single');
        Route::get('/popular', 'FrontendController@peoplePopular')->name('people.popular');
    });

    //search
    Route::get('/search/{keyword}', 'FrontendController@search')->name('search');

    // Genres
    Route::get('/genre/{id}/{slug?}', 'FrontendController@genre')->where(['id' => '[0-9]+'])->name('genre');

    //Keyword
    Route::get('/keyword/{id}/{slug?}', 'FrontendController@keyword')->where(['id' => '[0-9]+'])->name('keyword');

    // Pages
    Route::get('page/{page}', 'FrontendController@pages')->name('page');

    // Loading
    Route::get('loading', 'FrontendController@loading')->name('loading');

    // Switch
    Route::get('switch/{locale}', 'LocaleController@switch')->name('locale.switch');

    // Sitemaps
    Route::group(['prefix' => 'sitemap'], function () {
        Route::get('/', 'SitemapController@index')->name('sitemap');

        Route::group(['prefix' => 'movie'], function () {
            Route::get('/', 'SitemapController@index');
            Route::get('popular', 'SitemapController@moviePopular');
            Route::get('top-rated', 'SitemapController@movieTopRated');
            Route::get('upcoming', 'SitemapController@movieUpcoming');
            Route::get('now-playing', 'SitemapController@movieNowPlaying');
        });

        Route::group(['prefix' => 'tv'], function () {
            Route::get('/', 'SitemapController@index');
            Route::get('popular', 'SitemapController@tvPopular');
            Route::get('top-rated', 'SitemapController@tvTopRated');
            Route::get('on-tv', 'SitemapController@tvOnTheAir');
            Route::get('airing-today', 'SitemapController@tvAiringToday');
        });
    });
});
