<?php

/*
|--------------------------------------------------------------------------
| 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!
|
*/
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

///* debugger mode control*/------------------------------------------------------------------------
Route::any('/debug', "DebugController@debug")->name('debug');
Route::post('/debug/ajax', "DebugController@userItemsAJAX");
// --must be deleted -------------------------------------------------------------------------------

//------- IMAGES ROUTES ----------------------------------------------------------------------------
Route::get('/image/{path}', 'ItemPicturesController@show')->name('images')->where(['path' => '.*']);
//------- END -> IMAGES ROUTES ---------------------------------------------------------------------

//------- SEARCH ROUTES ----------------------------------------------------------------------------
Route::post('/search', 'SphinxSearchController@search')->name('sphinx.search');
//------- END -> IMAGES ROUTES ---------------------------------------------------------------------

//------- ITEM ROUTEs ------------------------------------------------------------------------------
Route::group(['prefix' => 'item', 'as' => 'item'], function () {
    Route::get('/all', "ItemController@index")->name('.index');
    Route::get('/{item}', "ItemController@show")->name('.show');

    Route::middleware(['auth'])->group(function () {
        Route::get('/new', "ItemController@create")->name('.create');
        Route::post('/', "ItemController@store")->name('.store');
        Route::delete('/{item}', "ItemController@destroy")->name('.delete');
        Route::put('/{item}', "ItemController@update")->name('.update');
        Route::post('/exchange/{item?}', 'ItemsExchangeOfferController@store')->name('.exchange.store');
//        Route::delete('/{item}', "ItemController@destroy")->middleware('can:destroy,item')->name('.delete');
//        Route::put('/{item}', "ItemController@update")->middleware('can:update,item')->name('.update');
    });
});
//------- END -> ITEM ROUTEs -----------------------------------------------------------------------

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

//------- ADMIN ROUTEs -----------------------------------------------------------------------------
Route::group(['prefix' => 'admin', 'middleware' => ['auth']], function () {
    Route::get('/', "Admin\AdminController@index")->name("admin.index");
//    Route::get('/items', "Admin\ItemsAdminController@index")->name("admin.items");
    Route::get('/items', "Admin\ItemsAdminController@index")->name("admin.items");
    Route::delete('/items/{id}', "Admin\ItemsAdminController@destroy")->name("admin.items.delete");
//    Route::put('/items/{id}', "Admin\ItemsAdminController@update")->name("admin.items.update");
    Route::post('/items/{id}', "Admin\ItemsAdminController@ajaxRequest")->name("admin.items.ajax");

    Route::get('/users', "Admin\UsersAdminController@index")->name("admin.users");
    Route::get('/categories', "Admin\AdminController@categories")->name("admin.categories");
});
//------- END -> ADMIN ROUTEs ----------------------------------------------------------------------

Route::group(['prefix' => 'user', 'middleware' => ['auth']], function () {
    Route::get('/item', 'UserItemController@index')->name("user.item");
//    Route::get('/{user}', 'UserController@show')->name("user.info");  // возможно стоит вынести за пределы Auth
//    Route::get('/offers-list', 'UserOffersController@index')->name("user.offers");
    Route::post('/items', 'ItemsInfoController@userItemsAJAX')->name('user.items.ajax');
//    Route::get('/item', "UserController@create")->name("item.create");
//    Route::get('/wishlist', 'UserController@wishList');
});

//--------- USERS ROUTES ---------------------------------------------------------------------------
Route::get('users/offers-list', 'UserOffersController@index')->name('user.offers')->middleware(['auth']);
Route::get('users/offers-archive', 'UserOffersController@archive')->name('user.offers.archive')->middleware(['auth']);
//Route::get('users/offers-to-user', 'UserOffersController@index')->name('user.offers.to')->middleware(['auth']);
//Route::get('users/offers-from-user', 'UserOffersController@index')->name('user.offers.from')->middleware(['auth']);

//Route::get('/users/item/index', 'UsersItemController@index');

Route::group(['prefix' => 'users', 'middleware' => ['auth']], function () {
    Route::get('/item/index', 'UsersItemController@index');
    Route::get('/item', 'UsersItemController@create')->name('user.item.create');
    Route::post('/item/', 'UsersItemController@store')->name('item.store');
    Route::any('/form/ajax', "RegisterItemController@jsonSubcategoryRequest")->name('form.ajax');

    Route::get('/home', "ProfileController@index")->name('home');
    Route::any('/items', "ProfileController@showAllItems")->name('user.items');

    Route::get('/profile', "RegisterProfileController@create")->name('user.profile');
    Route::post('/profile', "RegisterProfileController@store")->name('user.profile.store');

});

//------- OUT OF AUTH ROUTEs -----------------------------------------------------------------------
Route::get('/dashboard', 'DashboardController@index')->name('dashboard');
Route::get('/category/{id}', 'DashboardController@category')->name('dashboard.category');
Route::post('/dashboard/query', 'DashboardController@fromCategories');
Route::get('/item/{item}', 'ItemsInfoController@show')->name('item.info');     /// это должен быть ItemController@show
//------- END -> UT OF AUTH ROUTEs -----------------------------------------------------------------

/**  Auth::routes();
 * // Authentication Routes...
 * Route::get('login', 'Auth\LoginController@showLoginForm')->name('login');
 * Route::post('login', 'Auth\LoginController@login');
 * Route::post('logout', 'Auth\LoginController@logout');
 *
 * // Registration Routes...
 * Route::get('register', 'Auth\RegisterController@showRegistrationForm');
 * Route::post('register', 'Auth\RegisterController@register');
 *
 * // Password Reset Routes...
 * Route::get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm');
 * Route::post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail');
 * Route::get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm');
 * Route::post('password/reset', 'Auth\ResetPasswordController@reset');
 */

Auth::routes();

//Route::get('/', 'HomeController@welcome')->name('welcome');
Route::get('/home', 'HomeController@index');