<?php

use App\Models\Invoice;
use App\Models\Leads;
use Illuminate\Support\Facades\Route;
// use Illuminate\Support\Facades\Hash;
// use App\User;
/*
|--------------------------------------------------------------------------
| 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('/cleareverything', function () {
    Artisan::call('cache:clear');
    Artisan::call('config:clear');
    Artisan::call('view:clear');
    Artisan::call('route:clear');
    Artisan::call('storage:link');
    echo "cleared";
});

Route::get('send-mail', function () {

    $invoice_mail = Invoice::find(1);
    $details = [
        'to' => $invoice_mail->email,
        'price' => $invoice_mail->invoiceItems->sum('price'),
        'services' => $invoice_mail->invoiceItems,
        'name' => $invoice_mail->name,
        'slug' => $invoice_mail->slug,
        'due_date' => $invoice_mail->due_date,
        'invoice_no' => $invoice_mail->id,
    ];
    return new \App\Mail\InvoiceMail($details);
});

// Route::get('/change-password', function(){
//     $user = User::find(28);
    
//     if ($user) {
//         $user->update([
//             'password' => Hash::make('roy.digi@1234'),
//         ]);
//         return "Password updated successfully.";
//     } else {
//         return "User not found.";
//     }
// });


Auth::routes(['register'=>false]);

Route::get('user/login','FrontendController@login')->name('login.form');
Route::post('user/login','FrontendController@loginSubmit')->name('login.submit');
Route::get('user/logout','FrontendController@logout')->name('user.logout');

Route::get('user/register','FrontendController@register')->name('register.form');
Route::post('user/register','FrontendController@registerSubmit')->name('register.submit');
// Reset password
Route::get('password-reset', 'FrontendController@showResetForm')->name('password.reset'); 
// Socialite 
Route::get('login/{provider}/', 'Auth\LoginController@redirect')->name('login.redirect');
Route::get('login/{provider}/callback/', 'Auth\LoginController@Callback')->name('login.callback');

// Home page routes
Route::redirect('/', '/admin');
Route::redirect('/home', '/admin');

Route::get('/about','FrontendController@about')->name('about');
Route::get('/roadmap','FrontendController@roadmap')->name('roadmap');
Route::get('/stores','FrontendController@stores')->name('stores');
Route::get('/faqs','FrontendController@faqs')->name('faqs');
Route::get('/contact','FrontendController@contact')->name('contact');
// Home page routes

Route::get('/collections', 'FrontendController@allCollections')->name('collections');
Route::get('/collection/{slug}', 'FrontendController@getcollectionBySlug')->name('collection');
Route::get('/product/{slug}', 'FrontendController@productDetail')->name('product');

Route::get('/nfts', 'FrontendController@allNfts')->name('nfts');
Route::get('/nft/{slug}', 'FrontendController@getnftBySlug')->name('nft');
Route::post('/nftminted', 'FrontendController@nftMinted')->name('nft.minted');

Route::get('/verify', 'FrontendController@verify')->name('verify')->middleware('user');
Route::post('/verify/usage', 'FrontendController@verifyUsage')->name('verify.usage');

// Cart section
Route::post('/add-to-cart','CartController@addToCart')->name('add-to-cart')->middleware('user');
Route::get('cart-delete/{id}','CartController@cartDelete')->name('cart-delete');
Route::post('cart-clear','CartController@cartClear')->name('cart.clear');

Route::get('/checkout','CartController@checkout')->name('checkout')->middleware('user');
Route::post('cart/order','OrderController@store')->name('cart.order');

Route::get('order/pdf/{id}','OrderController@pdf')->name('order.pdf');


Route::get('/getPromo','FrontendController@getPromo')->name('getPromo');
Route::post('/promo/store','FrontendController@promoStore')->name('promo.store');
Route::post('/promo/apply','FrontendController@applyPromo')->name('promo.apply');
Route::get('/points','FrontendController@points')->name('points')->middleware('user');
Route::post('/withdrawRequest','FrontendController@withdrawRequest')->name('withdrawRequest')->middleware('user');

Route::get('/contact','FrontendController@contact')->name('contact');
Route::post('/contact/message','MessageController@store')->name('contact.store');

Route::get('product-detail/{slug}','FrontendController@productDetail')->name('product-detail');
Route::post('/product/search','FrontendController@productSearch')->name('product.search');
Route::get('/product-cat/{slug}','FrontendController@productCat')->name('product-cat');
Route::get('/product-sub-cat/{slug}/{sub_slug}','FrontendController@productSubCat')->name('product-sub-cat');
Route::get('/product-brand/{slug}','FrontendController@productBrand')->name('product-brand');


// Wishlist
Route::get('/wishlist',function(){
    return view('frontend.pages.wishlist');
})->name('wishlist');
Route::get('/wishlist/{slug}','WishlistController@wishlist')->name('add-to-wishlist')->middleware('user');
Route::get('wishlist-delete/{id}','WishlistController@wishlistDelete')->name('wishlist-delete');

Route::get('/income','OrderController@incomeChart')->name('product.order.income');
Route::get('/user/chart','AdminController@userPieChart')->name('user.piechart');
Route::get('/product-grids','FrontendController@productGrids')->name('product-grids');
Route::get('/product-lists','FrontendController@productLists')->name('product-lists');
Route::match(['get','post'],'/filter','FrontendController@productFilter')->name('shop.filter');
// Order Track
Route::get('/product/track','OrderController@orderTrack')->name('order.track');
Route::post('product/track/order','OrderController@productTrackOrder')->name('product.track.order');

// NewsLetter
Route::post('/subscribe','FrontendController@subscribe')->name('subscribe');

// Product Review
Route::resource('/review','ProductReviewController');
Route::post('product/review','ProductReviewController@store')->name('review.store');

// Post Comment 
Route::post('post/{slug}/comment','PostCommentController@store')->name('post-comment.store');
Route::resource('/comment','PostCommentController');
// Coupon
Route::post('/coupon-store','CouponController@couponStore')->name('coupon-store');
// Payment
Route::get('payment', 'PayPalController@payment')->name('payment');
Route::get('cancel', 'PayPalController@cancel')->name('payment.cancel');
Route::get('payment/success', 'PayPalController@success')->name('payment.success');

Route::get('/invoice/{slug}','InvoiceController@payInvoice')->name('invoice.payment');
Route::post('/invoice/{slug}','InvoiceController@submitPayment')->name('invoice.submitPayment');
Route::get('/invoice/pdf/{slug}','InvoiceController@pdf')->name('invoice.pdf');


// Backend section start
Route::post('stripe/stripe_webhook', 'StripeController@webhookHandle')->name('stripe.webhook');

Route::group(['prefix'=>'/admin','middleware'=>['auth','admin']],function(){
    Route::get('/','AdminController@index')->name('admin');
    // invoice 
    Route::get('invoice/merchant-details', 'InvoiceController@merchantData')->name('merchant.lists');
    Route::resource('invoice','InvoiceController');
    // leads 
    
    Route::resource('leads','LeadsController');
    Route::post('leads/delete/test', 'LeadsController@deleteAllTest')->name('leads.deleteAllTest');
    Route::get('/file-manager',function(){
        return view('backend.layouts.file-manager');
    })->name('file-manager');
    // user route
    Route::resource('users','UsersController');
    // Banner
    Route::resource('banner','BannerController');
    // Colors
    Route::resource('colors','ColorsController');
    // Size
    Route::resource('size','SizeController');
    // Collection
    // Route::resource('collection','CollectionController');
    // Profile
    Route::get('/profile','AdminController@profile')->name('admin-profile');
    Route::post('/profile/{id}','AdminController@profileUpdate')->name('profile-update');
    // payment-gateways
    Route::get('/payment-gateways','AdminController@paymentGateways')->name('gateways.index');
    // currency
    Route::get('/currency','AdminController@currency')->name('currency.index');
    // Category
    Route::resource('/category','CategoryController');
    // Product
    Route::resource('/product','ProductController');
    // Ajax for sub category
    Route::post('/category/{id}/child','CategoryController@getChildByParent');
    // POST category
    Route::resource('/post-category','PostCategoryController');
    // Post tag
    Route::resource('/post-tag','PostTagController');
    // Post
    Route::resource('/post','PostController');
    // Message
    Route::resource('/message','MessageController');
    Route::get('/message/five','MessageController@messageFive')->name('messages.five');

    // Order
    Route::resource('/order','OrderController');
    // Shipping
    Route::resource('/shipping','ShippingController');
    // Coupon
    Route::resource('/coupon','CouponController');
    // Settings
    Route::get('settings','AdminController@settings')->name('settings');
    Route::post('setting/update','AdminController@settingsUpdate')->name('settings.update');

    // Points
    Route::get('allPromo','AdminController@allPromo')->name('allPromo');
    Route::get('promo/used','AdminController@promoUsed')->name('promo.used');

    Route::get('allRequest','AdminController@allRequest')->name('allRequest');
    Route::get('request/edit/{id}','AdminController@editRequest')->name('request.edit');
    Route::post('request/update/{id}','AdminController@updateRequest')->name('request.update');

    // Notification
    Route::get('/notification/{id}','NotificationController@show')->name('admin.notification');
    Route::get('/notifications','NotificationController@index')->name('all.notification');
    Route::delete('/notification/{id}','NotificationController@delete')->name('notification.delete');
    // Password Change
    Route::get('change-password', 'AdminController@changePassword')->name('change.password.form');
    Route::post('update-password', 'AdminController@changPasswordStore')->name('update.password');
});










// User section start
Route::group(['prefix'=>'/user','middleware'=>['user']],function(){
    Route::get('/','HomeController@index')->name('user');
     // Profile
     Route::get('/profile','HomeController@profile')->name('user-profile');
     Route::post('/profile/{id}','HomeController@profileUpdate')->name('user-profile-update');
    //  Order
    Route::get('/order',"HomeController@orderIndex")->name('user.order.index');
    Route::get('/order/show/{id}',"HomeController@orderShow")->name('user.order.show');
    Route::delete('/order/delete/{id}','HomeController@userOrderDelete')->name('user.order.delete');
    // Product Review
    Route::get('/user-review','HomeController@productReviewIndex')->name('user.productreview.index');
    Route::delete('/user-review/delete/{id}','HomeController@productReviewDelete')->name('user.productreview.delete');
    Route::get('/user-review/edit/{id}','HomeController@productReviewEdit')->name('user.productreview.edit');
    Route::patch('/user-review/update/{id}','HomeController@productReviewUpdate')->name('user.productreview.update');
    
    // Post comment
    Route::get('user-post/comment','HomeController@userComment')->name('user.post-comment.index');
    Route::delete('user-post/comment/delete/{id}','HomeController@userCommentDelete')->name('user.post-comment.delete');
    Route::get('user-post/comment/edit/{id}','HomeController@userCommentEdit')->name('user.post-comment.edit');
    Route::patch('user-post/comment/udpate/{id}','HomeController@userCommentUpdate')->name('user.post-comment.update');
    
    // Password Change
    Route::get('change-password', 'HomeController@changePassword')->name('user.change.password.form');
    Route::post('change-password', 'HomeController@changPasswordStore')->name('change.password');

});

Route::group(['prefix' => 'laravel-filemanager', 'middleware' => ['web', 'auth']], function () {
    \UniSharp\LaravelFilemanager\Lfm::routes();
});

