<?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' => '.*']);
//------- SEARCH ROUTES ----------------------------------------------------------------------------
Route::post('/search', 'SphinxSearchController@search')->name('sphinx.search');
//------- MAIL ROUTES ------------------------------------------------------------------------------
Route::post('/mail', "MailSettingController@sendForm")->name('mail.send');



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

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



//------- 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::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@ajaxItemsRequest")->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::any('/ausers', "Admin\UsersAdminController@ajaxUsersRequest")->name("admin.users.ajax");
//Route::any('/ausers/{id?}', function($id =null){
//    return dump('123123');
//})->name("admin.users.ajax");

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

    Route::post('/{user}', "UsersAdminController@ajaxUserEditRequest")->name('user.edit');

    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');

    Route::post('/items/ajax', 'ItemsInfoController@userItemsAJAX')->name('user.items.ajax');
    Route::post('/item/{item}', 'ItemsInfoController@userItemModifyAJAX')->name('user.item.modify.ajax');
});
//------- END -> USERS ROUTEs ----------------------------------------------------------------------



//------- 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('users/offers-list', 'UserOffersController@index')->name('user.offers')->middleware(['auth']);
Route::get('users/offers-archive', 'UserOffersController@archive')->name('user.offers.archive')->middleware(['auth']);
//------- END -> UT OF AUTH ROUTEs -----------------------------------------------------------------



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