<?php
/*
    * Created by VahabDev in Aparat Live
    * Website: https://pourfi.ir
    * Aparat Live: https://www.aparat.com/vahabdev/live
    * Aparat Channel: https://www.aparat.com/vahabdev
    * Rubika Channel: https://rubika.ir/vahabdev
    * Donate: https://reymit.ir/vahabdev
    * Telegram: https://t.me/vahabdev
*/


use App\Http\Controllers\invoiceController;
use App\Http\Controllers\orderController;
use App\Http\Controllers\profileController;
use App\Http\Controllers\ticketController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\authController;
use App\Http\Controllers\dashboardController;
use App\Http\Controllers\indexController;
use App\Http\Controllers\productController;
use App\Http\Controllers\blogController;
use App\Http\Controllers\cartController;
use App\Http\Controllers\commentController;
use App\Http\Controllers\pageController;
use App\Http\Controllers\InstallerController;


//Install

Route::get('/install', [InstallerController::class, 'index'])->name('installer.index');
Route::post('/install/step1', [InstallerController::class, 'processStep1'])->name('installer.processStep1');
Route::get('/install/step2', [InstallerController::class, 'step2'])->name('installer.step2');
Route::post('/install/step2', [InstallerController::class, 'processStep2'])->name('installer.processStep2');
Route::get('/install/step3', [InstallerController::class, 'step3'])->name('installer.step3');
Route::post('/install/finish', [InstallerController::class, 'finish'])->name('installer.finish');
Route::get('/install/success', [InstallerController::class, 'success'])->name('installer.success');



Route::middleware(['CheckInstall'])->group(function () {
    Route::get('/', [indexController::class, 'index'])->name('index');

    //products
    Route::get('/product/all', [productController::class, 'allProducts'])->name('product.all');
    Route::get('/product/{slug}', [productController::class, 'single'])->name('product.view');
    Route::get('/pro_cat/{slug}', [productController::class, 'productCategorys'])->name('product.cat');

    //SendComment
    Route::post('/comment/{type}/{id}', [commentController::class, 'sendComment'])->name('sendComment');


    //WebLog
    Route::get('/post/all', [blogController::class, 'allPosts'])->name('blog.all');
    Route::get('/post/{slug}', [blogController::class, 'singlePost'])->name('blog.view');
    Route::get('/post_cat/{slug}', [blogController::class, 'postCategorys'])->name('blog.cat');


    //page
    Route::get('/page/{slug}', [pageController::class, 'view'])->name('page.view');


    //قبل از ورود
    // احراز هویت
    Route::middleware(['CheckNoLogin'])->group(function () {

        //for login and register and reset password
        Route::get('/login', [authController::class, 'index'])->name('login');
        Route::post('/dologin', [authController::class, 'dologin'])->name('dologin');

        Route::get('/register', [authController::class, 'register'])->name('register');
        Route::post('/doregister', [authController::class, 'doregister'])->name('doregister');




    });



    //بعد از ورود
    // پنل کاربری
    Route::middleware(['CheckLogin'])->group(function () {

        Route::prefix('client')->group(function () {
            Route::get('/logout', [authController::class, 'logout'])->name('logout');

            Route::get('/dashboard', [dashboardController::class, 'index'])->name('dashboard');
            Route::get('/profile', [profileController::class, 'index'])->name('profile');
            Route::post('/doUpdateProfile', [profileController::class, 'doUpdateProfile'])->name('doUpdateProfile');

            Route::get('/changepass', [profileController::class, 'changepass'])->name('changepass');

            Route::post('/dochangepass', [profileController::class, 'dochangepass'])->name('dochangepass');

            Route::get('/orders', [orderController::class, 'index'])->name('orders');
            Route::get('/order/{id}', [orderController::class, 'show'])->name('order.show');
            Route::get('/download/{orderid}/{id}', [orderController::class, 'DownloadFile'])->name('order.download');



            //Invoices
            Route::get('/invoices', [invoiceController::class, 'index'])->name('invoice.list');
            Route::get('/invoice/{id}', [invoiceController::class, 'show'])->name('invoice.view');

            Route::get('/payment/{id}', [invoiceController::class, 'PaymentStart'])->name('invoice.payment');
            Route::post('/callback/{id}', [invoiceController::class, 'CallbackPayment'])->name('invoice.callback');



            Route::get('/tickets', [ticketController::class, 'index'])->name('tickets');
            Route::get('/ticket/{id}', [ticketController::class, 'view'])->name('ticket.show');
            Route::get('/open_ticket', [ticketController::class, 'open'])->name('ticket.open');
            Route::get('/close_ticket', [ticketController::class, 'close'])->name('ticket.close');


            Route::post('/doopen', [ticketController::class, 'doOpen'])->name('ticket.doOpen');
            Route::post('/doReplay/{id}', [ticketController::class, 'doReplay'])->name('ticket.doReplay');



            //carthaye man
            Route::get('/cart/add/{id}', [cartController::class, 'addToCart'])->name('cart.add');
            Route::get('/cart/view', [cartController::class, 'viewCart'])->name('cart.view');
            Route::get('/cart/remove/{id}', [cartController::class, 'removeFromCart'])->name('cart.remove');

            Route::post('/cart/complate', [cartController::class, 'complateCart'])->name('cart.complate');

        });




    });


});



Route::fallback(function () {
    if (!file_exists(storage_path('installed'))) {
        return redirect()->route('installer.index');
    }
    return abort(404);
});
