<?php

use Illuminate\Support\Facades\Route;
use App\Models\Lobby;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

// old routes
/*
Route::get('/', function () {
    return view('start');
});

Route::get('/ll-test', function () {
    return view('TEST.sub');
});

Route::get('/join/{meetingID}', function () {
    return view('join');
});

Route::get('/meeting/{meetingID}/{participantID}', 'GuestController@meeting');
*/

Route::get('/join', function () {
    return view('join');
});
Route::get('/get-client-checkin-token/{uid}', 'GuestController@getCheckinToken');
Route::get('/meet', 'GuestController@meet');

// Route::middleware('ensureNoValidProSession')->group(function(){
    Route::get('/', 'AppSessionController@proRequestSmsLogInToken')->name('pro-request-sms-login-token');
    Route::get('/pro/login', 'AppSessionController@proLogIn')->name('pro-login');
    Route::post('/pro/login', 'AppSessionController@processProLogIn')->name('process-pro-login');
// });

Route::middleware('ensureValidProSession')->group(function(){
    Route::get('/dashboard', 'ProController@dashboard')->name('pro-dashboard');

    // old routes
//    Route::get("/pros", 'ProController@index')->name('pro-index');
//    Route::get("/pros/create", 'ProController@create')->name('pro-create');
//    Route::get("/pros/show/{uid}", 'ProController@show')->name('pro-show');

    Route::get('/pro/meet', 'ProController@meet');
    Route::get('/pro/get-opentok-session-key/{uid}', 'ProController@getOpentokSessionKey');

    Route::get('/pro/logout', 'AppSessionController@processProLogOut')->name('pro-logout');

    @include 'generated.php';

    Route::get('/mc/{fragment}', 'MeetingCenterController@mc')
        ->where('fragment', '.+')
        ->name('mc');

});

Route::post('/post-to-api', 'AppSessionController@postToAPI')->name('post-to-api');
Route::post('/post-to-api-ajax', 'AppSessionController@postToAPIAjax')->name('post-to-api-ajax');


Route::middleware('ensureOnlyStrangerSession')->group(function(){
	Route::get('/client/{url_slug}', 'ClientController@entranceLobby')->name('client-lobby');
});
Route::get('/client/meeting/{meeting_uid}', 'ClientController@entranceLobby')->name('join-meeting');

Route::bind('url_slug', function($value, $route)
{
    return Lobby::where('url_slug', $value)->first();
});

Route::get('/note/{note_uid}', 'NoteController@renderNote')->name('render-note');
Route::get('/select_section_template_form/{note_uid}', 'NoteController@selectSectionTemplateForm')->name('select_section_template_form');
Route::get('/section_create_form/{note_uid}/{section_template_uid}', 'NoteController@sectionCreateForm')->name('section_create_form');
Route::get('/section_update_form/{section_uid}', 'NoteController@sectionUpdateForm')->name('section_update_form');
Route::post("/process_form_submit", 'NoteController@processFormSubmit')->name('process_form_submit');
if (env('APP_ENV') === 'production') {
    URL::forceScheme('https');
}
