<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AppController;
use Itstructure\LaRbac\Http\Controllers\{UserController, RoleController, PermissionController};

use App\Http\Controllers\Admin\UserController as Admin;
use App\Http\Controllers\App\UserController as User;
use App\Http\Controllers\CheckoutController;

/*
|--------------------------------------------------------------------------
| 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!
|
*/



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

Route::get('/logout', function () {
    return view('welcome');
})->name('logout');
Route::get('/root', function () {
    return view('welcome');
})->name('root');

Route::get('/admin', [AppController::class, 'admin'])->name('admin');
Route::get('/admin/login', [App\Http\Controllers\Admin\LoginController::class, 'admin_login_form']);
Route::post('admin/login', [App\Http\Controllers\Admin\LoginController::class, 'admin_login'])->name('admin.login');


Route::get('/login', [User::class, 'login'])->name('login');
Route::post('/signup', [User::class, 'signup'])->name('signup');

//Language Translation
Route::get('/translate/{locale}', [AppController::class, 'lang'])->name('translate');
Route::get('/products', [CheckoutController::class, 'index'])->name('checkout.index');
Route::get('/checkout', [CheckoutController::class, 'checkout'])->name('checkout');
Route::get('/add-to-cart/{id}', [CheckoutController::class, 'add_to_cart'])->name('add.to.cart');




Route::group([
    'prefix' => 'admin',
    'middleware' => array_merge(
        is_array(config('rbac.routesAuthMiddlewares')) ? config('rbac.routesAuthMiddlewares') : ['auth'],
        !empty(config('rbac.routesMainPermission')) ? ['can:'.config('rbac.routesMainPermission')] : []
    )
], function () {

    Route::get('/dashboard', [AppController::class, 'dashboard'])->name('dashboard');
    Route::get('/usersnew', [UserController::class, 'index']);

    
    // Users (members)
    //Route::resource('users', 'App\Http\Controllers\Admin\UserController');
    Route::get('/users/customers', [Admin::class, 'customers'])->name('admin.customers');
    Route::get('/users/angels', [Admin::class, 'angels'])->name('admin.angels');
    Route::get('/users/staff', [Admin::class, 'staff'])->name('admin.staff');
    Route::get('/users/customer/add', [Admin::class, 'add_customer'])->name('add_customer_form');
    Route::get('/users/angel/add', [Admin::class, 'add_angel'])->name('add_angel_form');
    Route::post('/users/validate', [Admin::class, 'new_user_form_validate'])->name('user.validate');
    Route::post('/users/customer/store', [Admin::class, 'store_customer'])->name('add_customer');
    Route::get('/users/customer/edit/{id}', [Admin::class, 'edit_customer'])->name('edit_customer');
    Route::post('/users/customer/update/{id}', [Admin::class, 'update_customer'])->name('update_customer');
    Route::get('/users/angel/add', [Admin::class, 'add_angel'])->name('add_angel');
    Route::get('/users', [UserController::class, 'index'])
        ->name('list_usersss');
    Route::get('users/delete-kyc/{id}', [Admin::class, 'destroyUserDoc'])->name('user.delete-kyc');
    Route::get('/users/destroy/{user}', [Admin::class, 'customers'])->name('user.destroy');
    Route::get('/users/{user}/show', [Admin::class, 'show'])->name('user.show');



    Route::resource('assets', 'App\Http\Controllers\Admin\AssetController');
    Route::post('assets/validate', [App\Http\Controllers\Admin\AssetController::class, 'validate'])->name('asset.validate');
    Route::post('assets/{id}', [App\Http\Controllers\Admin\AssetController::class, 'update'])->name('assets.update');


    
    Route::resource('zap-pages', 'App\Http\Controllers\Admin\CmsController');
    Route::post('zap-pages/validate', [App\Http\Controllers\Admin\CmsController::class, 'validate'])->name('zap-pages.validate');
    Route::post('zap-pages/{zap_page}', [App\Http\Controllers\Admin\CmsController::class, 'update'])->name('zap-pages.update');
    Route::get('zap-pages/delete-form-field/{id}', [App\Http\Controllers\Admin\CmsController::class, 'destroyFormField'])->name('zap-pages.delete-form-field');
    Route::get('zap-pages/delete-form-button/{id}', [App\Http\Controllers\Admin\CmsController::class, 'destroyFormButton'])->name('zap-pages.delete-form-button');


    
    Route::get('settings', [App\Http\Controllers\Admin\SettingController::class, 'index'])->name('settings.index');
    Route::post('settings/store', [App\Http\Controllers\Admin\SettingController::class, 'store'])->name('settings.store');




    Route::get('show/{id}', [UserController::class, 'show'])
        ->name('show_user');

    Route::get('edit/{id}', [UserController::class, 'edit'])
        ->name('edit_user');

    Route::post('update/{id}', [UserController::class, 'update'])
        ->name('update_user');

    Route::post('delete', [UserController::class, 'delete'])
        ->name('delete_user');

    // Roles

    Route::get('/roles', [RoleController::class, 'index'])
        ->name('list_roles');

    Route::get('show/{id}', [RoleController::class, 'show'])
        ->name('show_role');

    Route::get('create', [RoleController::class, 'create'])
        ->name('create_role');

    Route::get('edit/{role}', [RoleController::class, 'edit'])
        ->name('edit_role');

    Route::post('store', [RoleController::class, 'store'])
        ->name('store_role');

    Route::post('update/{role}', [RoleController::class, 'update'])
        ->name('update_role');

    Route::post('/delete', [RoleController::class, 'delete'])
        ->name('delete_role');
   
    // Permissions

    Route::get('/permissions', [PermissionController::class, 'index'])
        ->name('list_permissions');

    Route::get('show/{id}', [PermissionController::class, 'show'])
        ->name('show_permission');

    Route::get('create', [PermissionController::class, 'create'])
        ->name('create_permission');

    Route::get('edit/{permission}', [PermissionController::class, 'edit'])
        ->name('edit_permission');

    Route::post('store', [PermissionController::class, 'store'])
        ->name('store_permission');

    Route::post('update/{permission}', [PermissionController::class, 'update'])
        ->name('update_permission');

    Route::post('delete', [PermissionController::class, 'delete'])
        ->name('delete_permission');
});

