<?php
// Routes using the web middleware

require "login.php";

Route::get('/about/terms', function () {
    return view('about.terms');
});

Route::get('/about/privacy', function () {
    return view('about.privacy');
});

Route::get('/', function () {
    if (!Auth::guest()) {
        return redirect(route('profile.view', Auth::user()->name));
    }
    return view('welcome');
});

Route::group(['middleware' => 'auth'], function () {
    // Table resource
    Route::group([
        'prefix' => 'table',
    ], function () {
        Route::get('create', 'TableController@create')->name('table.create');
        Route::post('create', 'TableController@storeNew')->name('table.storeNew');
    });

    Route::group([
        'prefix' => 'profile',
    ], function () {
        Route::get('edit', 'ProfileController@editProfile')->name('profile.edit');
        Route::post('store', 'ProfileController@storeProfile')->name('profile.store');
    });

    Route::group([
        'prefix' => 'account',
    ], function () {
        Route::get('edit', 'AccountController@editAccount')->name('account.edit');
        Route::post('store', 'AccountController@storeAccount')->name('account.store');
        Route::get('forget-social-login/{id}', 'AccountController@forgetSocialLogin')->name('forget-identity');
    });
});

// Table resource - located at the end to work as a fallback
Route::get('@{user}', 'ProfileController@view')->name('profile.view');
Route::get('@{user}/{table}', 'TableController@view')->name('table.view');