<?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 App\Http\Controllers\LoginController;
use App\Http\Controllers\OrderArchiveController;
use App\Http\Controllers\OrderController;
use App\Http\Controllers\PriceListController;
use App\Http\Controllers\ProductController;
use App\Http\Controllers\SupplierController;
use App\Http\Controllers\TestController;
use Illuminate\Support\Facades\Route;

// auth()->loginUsingId(1);
// auth()->logout();

if (in_array(strtolower(env('APP_STAGE')), ['d2dtst', 'e2etst'])) {
    echo view('layout.wherehere')->render();
    exit();
}
if (! in_array(strtolower(env('APP_STAGE')), ['d2dtst', 'e2etst', 'dev','local'])) {
    URL::forceScheme('https');
} else {
    URL::forceScheme('http');
}

Route::get('/l', function () {
    $M = \App\Models\ProfitCenter::where('name', 'like', 'pro%');
    dd(getSql($M));
    dd($M);
    dd(Illuminate\Support\Str::replaceArray('?', $M->getBindings(), $M->toSql())
    );
    dd($M->getBindings());

    dd(DB::table('profitcenters')->mergeBindings($M->getQuery()))->toSql();
    dd(auth()->user());
    Debugbar::info('sdsd');

    return view('layout.wherehere');
    // var_export(route('login'));
    echo '<pre>';

})->name('l');

Route::get('/test', [TestController::class, 'test'])->name('test');

Route::post('/login', [LoginController::class, 'authenticate'])->name('login');
Route::get('/logout', function () {
    Auth::logout();
    \request()->session()->invalidate();
    \request()->session()->regenerateToken();

    return redirect('/');
})->name('logout');

Route::get('/orderFeedback/{feedbackId}', [\App\Http\Controllers\SupplierFeedbackController::class, 'orderFeedback'])->name('orderFeedback');

Route::get('/', function () {
    if (! auth()->check()) {
        return view('layout.login');
    }
    /*    Debugbar::info('debugBarinfo'.basename(__FILE__).':'.__LINE__);
        \Log::channel('BrowserConsole')->info('BrowserConsole',['basename'=>basename(__FILE__),'line'=>__LINE__]);
        \Log::channel('chromePHP')->info('chromePHP'.basename(__FILE__).':'.__LINE__);
        \Log::channel('firePHP')->info('firePHP'.basename(__FILE__).':'.__LINE__);*/
    $viewData['site'] = env('APP_STAGE', 'DEV');

    return view('layout.core')->with($viewData);
    // return view('welcome');
})->name('landing');

Route::resource('/dashboard', \App\Http\Controllers\DashboardController::class);

Route::prefix('order')->name('order.')->group(function () {
    // csak bemutatora fixalva
    Route::get('getDataTableContent', [OrderController::class, 'getDataTableContent'])->name('getDataTableContent');
    Route::get('/{id}/checkReadyToSend', [OrderController::class, 'checkReadyToSend'])->name('checkReadyToSend');
    Route::resource('/', OrderController::class)->parameters(['' => 'id']);

});
Route::prefix('orderArchive')->name('orderArchive.')->group(function () {
    // csak bemutatora fixalva
    Route::get('getDataTableContent', [OrderArchiveController::class, 'getDataTableContent'])->name('getDataTableContent');
    Route::resource('', OrderArchiveController::class)->only([
        'index', 'show', 'edit',
    ])->parameters(['' => 'id']);
});

Route::prefix('product')->name('product.')->group(function () {
    Route::post('/{id}/toggleFavorites', [ProductController::class, 'toggleFavorites'])->name('toggleFavorites');
});
/*Route::resource('supplier', SupplierController::class)->only([
    'index','show'
]);*/

Route::prefix('priceList')->name('priceList.')->group(function () {
    Route::get('getDataTableContent', [PriceListController::class, 'getDataTableContent'])->name('getDataTableContent');
    Route::resource('/', PriceListController::class)->parameters(['' => 'id']);
});

Route::prefix('supplier')->name('supplier.')->group(function () {
    Route::get('getDataTableContent', [SupplierController::class, 'getDataTableContent'])->name('getDataTableContent');
    Route::resource('/', SupplierController::class)->parameters(['' => 'id'])->only([
        'index', 'show',
    ]);
});

/*
Route::get('/order', function () {
    return view('modules.order');
    //return view('welcome');
})->name('order');
*/

/*
 * Admin section
 */
use App\Http\Controllers\Admin\AddressController;
use App\Http\Controllers\Admin\ContactController as ContactControllerAdmin;
use App\Http\Controllers\Admin\ExportController;
use App\Http\Controllers\Admin\FileBatchUploadController as FileBatchUploadControllerAlias;
use App\Http\Controllers\Admin\PriceListController as PriceListControllerAdmin;
use App\Http\Controllers\Admin\PriceListProfitCenterController;
use App\Http\Controllers\Admin\ProductController as ProductControllerAdmin;
use App\Http\Controllers\Admin\ProductGroupController;
use App\Http\Controllers\Admin\ProfitCenterController as ProfitCenterControllerAdmin;
use App\Http\Controllers\Admin\StatisticsController;
use App\Http\Controllers\Admin\SupplierController as SupplierControllerAdmin;
use App\Http\Controllers\Admin\SystemParametersController as SystemParametersControllerAdmin;

Route::prefix('admin')->name('admin.')->group(function () {

    Route::prefix('statistics')->name('statistics.')->group(function ($request) {
        // dd($request);
        // Route::get('getDataTableContent',[SupplierControllerAdmin::class,'getDataTableContent'])->name('getDataTableContent');
        // dd('hello');
        Route::get('getProductSearch', [StatisticsController::class, 'getProductSearch'])->name('getProductSearch');
        Route::post('getStat', [StatisticsController::class, 'getStat'])->name('getStat');
        Route::resource('/', StatisticsController::class)->only([
            'index', 'show',
        ])->parameters(['' => 'statType']);

        // ->parameters([''=>'supplier']);
    });

    /*    Route::prefix('statistics')->name('statistics.')->group(
            function (){
                Route::resource('Statistics', StatisticsController::class)->only([
                    'index','store'
                ]);
            }
        );*/

    Route::prefix('productGroup/getTreeNode')->name('productGroup.Tree.')->group(
        function () {
            Route::post('/', [ProductGroupController::class, 'treeNodeGet'])->name('getNode');
            Route::post('content/{id}', [ProductGroupController::class, 'treeNodeGetContent'])->name('getNodeContent');
            Route::post('create/', [ProductGroupController::class, 'treeNodeAdd'])->name('createNew');
            Route::post('rename/{id}', [ProductGroupController::class, 'treeNodeRename'])->name('rename');
            Route::post('move/{id}', [ProductGroupController::class, 'treeNodeMove'])->name('move');
            Route::post('delete/{id}', [ProductGroupController::class, 'treeNodeDelete'])->name('delete');

        }

    );
    // Route::post('productGroup/getTreeNode',[ProductGroupController::class,'getTreeNode'])->name('productGroup.getTreeNode');
    Route::resource('productGroup', ProductGroupController::class)->only([
        'index', 'store',
    ]);
    // Route::resource('/supplier', SupplierControllerAdmin::class);
    Route::prefix('supplier')->name('supplier.')->group(function () {
        Route::get('getDataTableContent', [SupplierControllerAdmin::class, 'getDataTableContent'])->name('getDataTableContent');
        Route::post('/{id}/attachFile', [SupplierControllerAdmin::class, 'attachFile'])->name('attachFile');
        Route::post('/{id}/detachFile', [SupplierControllerAdmin::class, 'detachFile'])->name('detachFile');
        Route::resource('/', SupplierControllerAdmin::class)->parameters(['' => 'supplier']);
    });

    Route::prefix('profitCenter')->name('profitCenter.')->group(function () {
        Route::get('getDataTableContent', [ProfitCenterControllerAdmin::class, 'getDataTableContent'])->name('getDataTableContent');
        Route::resource('/', ProfitCenterControllerAdmin::class)->parameters(['' => 'supplier']);
    });
    // Route::resource('profitCenter', ProfitCenterControllerAdmin::class);
    // Route::resource('product', ProductControllerAdmin::class);
    Route::prefix('product')->name('product.')->group(function () {
        Route::get('getDataTableContent', [ProductControllerAdmin::class, 'getDataTableContent'])->name('getDataTableContent');
        Route::post('/{id}/attachFile', [ProductControllerAdmin::class, 'attachFile'])->name('attachFile');
        Route::post('/{id}/detachFile', [ProductControllerAdmin::class, 'detachFile'])->name('detachFile');
        Route::resource('/', ProductControllerAdmin::class)->parameters(['' => 'product']);
    });

    Route::get('priceList/getDataTableContent', [PriceListControllerAdmin::class, 'getDataTableContent'])->name('priceList.getDataTableContent');
    Route::resource('priceList', PriceListControllerAdmin::class);

    Route::get('priceListProfitCenter/getDataTableContent', [PriceListProfitCenterController::class, 'getDataTableContent'])->name('priceListProfitCenter.getDataTableContent');
    Route::get('priceListProfitCenter/getProductGroupHTML', [PriceListProfitCenterController::class, 'getProductGroupHTML'])->name('priceListProfitCenter.getProductGroupHTML');
    Route::resource('priceListProfitCenter', PriceListProfitCenterController::class);

    Route::resource('fileBatchUpload', FileBatchUploadControllerAlias::class);
    Route::post('fileBatchUpload/upload', [FileBatchUploadControllerAlias::class, 'upload'])->name('fileBatchUpload.upload');
    /*
        */

    Route::resource('contact', ContactControllerAdmin::class)->only(['index', 'show', 'store', 'update']);
    Route::resource('address', AddressController::class)->only(['index', 'show', 'store', 'update']);
    Route::resource('systemParameters', SystemParametersControllerAdmin::class);
    Route::resource('export', ExportController::class);

});
