<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Admin\AuthController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\JewelryController;
use App\Imports\JewelryImport;
use App\Http\Controllers\GoldController;
use App\Http\Controllers\Admin\SettingController;
use App\Http\Controllers\Admin\CartController;
use App\Http\Controllers\Admin\UserController;
use App\Http\Controllers\Frontend\FrontendController;
use App\Http\Controllers\Frontend\LoginController;
use App\Http\Controllers\Admin\OrderController;
use App\Http\Controllers\Admin\DiamondPricingController;



/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

        // Route::get('/', function () {
        //     return view('welcome');
        // });
        // Route::get('/',[LoginController::class,'login'])->name('frontend.login');


        // Route::get(
        //     '/login',
        //     [LoginController::class,'login']
        // )->name('frontend.login');

        Route::get('/', [LoginController::class,'login']);

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

        Route::post(
            '/login-check',
            [LoginController::class,'loginCheck']
        )->name('loginCheck');

        // Route::get(
        //     '/logout',
        //     [LoginController::class,'logout']
        // )->name('logout');

        // Route::post('/logout', function () {

        // Auth::logout();

        // request()->session()->invalidate();

        // request()->session()->regenerateToken();

        // return redirect('/login');

        // })->name('logout');
        
        Route::post('/logout', [LoginController::class, 'logout'])
    ->name('logout');
        // Route::get('/login-page',[LoginController::class, 'loginPage'])->name('login');

        Route::get(
            '/register-page',
            [LoginController::class, 'register']
        )->name('register-page');

        Route::post(
        '/register',
        [LoginController::class,'register_form']
        )->name('register');

        Route::get(
            '/products',
            [FrontendController::class, 'products']
        )->name('products');

        Route::get(
        '/product-detail/{id}',
        [FrontendController::class, 'productDetail']
        )->name('product.detail');

        Route::post(
            '/add-to-cart',
            [FrontendController::class,'addToCart']
        )->name('add.to.cart');

    // web.php

        Route::get(
            '/cart',
            [FrontendController::class,'cart']
        )->name('cart');

        Route::post(
            '/cart-qty-update',
            [FrontendController::class,'updateQty']
        )->name('cart.qty.update');

        Route::get(
            '/remove-cart/{id}',
            [FrontendController::class,'removeCart']
        );

        Route::post(
            '/place-order',
            [FrontendController::class,'placeOrder']
        )->name('place.order');

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

        Route::get('/', [AuthController::class, 'showLogin'])->name('admin.login');
        Route::post('/login', [AuthController::class, 'login']);

        Route::middleware('auth')->group(function () {
        Route::get('/dashboard', [DashboardController::class, 'index'])->name('admin.dashboard');
        });
        
        Route::post(
        '/product-variation',
        [FrontendController::class, 'productVariation']
    )->name('product.variation');


        Route::post('/admin/logout', [AuthController::class, 'logout'])->name('admin.logout');

        // Route::get('/admin/verify-otp', [AuthController::class, 'otpForm']);
        // Route::post('/admin/verify-otp', [AuthController::class, 'verifyOtp']);

        

        Route::get('/admin/otp', [AuthController::class, 'otpForm'])
    ->name('admin.otp.form');

    Route::post('/admin/otp', [AuthController::class, 'verifyOtp'])
    ->name('admin.otp.verify');

        // Route::post('jewelry_import', [JewelryImport::class, 'import'])->name('jewelry.import');
        // Route::get('/importPage', [JewelryController::class, 'importPage'])->name('admin.importPage');

        // Route::post('jewelry_import', [JewelryController::class, 'import'])->name('jewelry.import');
        // Route::get('/importPage', [JewelryController::class, 'importPage'])->name('admin.importPage');


        Route::get('/importPage', [JewelryController::class, 'importPage'])->name('admin.importPage');

        Route::post('/jewelry_import', [JewelryController::class, 'import'])->name('jewelry.import');

        Route::get('/product', [JewelryController::class, 'products'])->name('product');

        Route::get('/products/ajax', [JewelryController::class, 'product_data'])->name('products.ajax');

       
        Route::get('/gold-price', [GoldController::class, 'getGoldPrice']);
       

        // Route::get('/admin/gold-setting', [SettingController::class, 'index'])->name('admin.gold-setting');
        // Route::post('/admin/gold-setting', [SettingController::class, 'store']);
        Route::prefix('admin')->group(function () {

            Route::get('/gold-setting', [SettingController::class, 'index'])->name('admin.gold-setting');

            Route::post('/gold-setting', [SettingController::class, 'store'])->name('admin.gold-setting.store');

        });

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

        Route::get('/cart-items', [CartController::class, 'index'])
            ->name('admin.cart-items');
        Route::get('/jewelry/{id}/edit',
        [JewelryController::class, 'edit'])
        ->name('admin.jewelry.edit');

        Route::post('/jewelry/{id}/update',
        [JewelryController::class, 'update'])
        ->name('admin.jewelry.update');
        });

        Route::get('/gold-price',
        [JewelryController::class, 'gold_price'])
        ->name('gold.price');
    
    
        Route::get(
            '/user-list',
            [UserController::class, 'index'])->name('admin.users.list');

        Route::post(
            '/update-markup',
            [UserController::class, 'updateMarkup'])->name('update-markup');

        Route::post('/add-user', [UserController::class, 'addUser'])
        ->name('add-user');


        Route::post('/update-user',[UserController::class,'updateUser'])
        ->name('update.user');


        Route::get(
        '/admin/orders',
        [OrderController::class,'order_list']
        )->name('admin.orders');

        Route::get('/admin/user-logs', [UserController::class, 'userLogs'])
    ->name('admin.user.logs');



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

        Route::get('/diamond-pricing', [DiamondPricingController::class, 'index'])->name('diamond-pricing.index');

        Route::get('/diamond-pricing/list', [DiamondPricingController::class, 'list'])->name('diamond-pricing.list');

        Route::post('/diamond-pricing/store', [DiamondPricingController::class, 'store'])->name('diamond-pricing.store');

        Route::get('/diamond-pricing/edit/{id}', [DiamondPricingController::class, 'edit'])->name('diamond-pricing.edit');

        Route::post('/diamond-pricing/update/{id}', [DiamondPricingController::class, 'update'])->name('diamond-pricing.update');

        Route::delete('/diamond-pricing/delete/{id}', [DiamondPricingController::class, 'destroy'])->name('diamond-pricing.delete');

    });



});