<?php
use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Frontend\CartController;
use App\Http\Controllers\Frontend\CheckoutController;
use App\Http\Controllers\Frontend\ContactController;
use App\Http\Controllers\Frontend\HomeController;
use App\Http\Controllers\Frontend\PageController;
use App\Http\Controllers\Frontend\Payment\PaypalController;
use App\Http\Controllers\Frontend\Payment\TapController;
use App\Http\Controllers\Frontend\ProductController;
use App\Http\Controllers\Frontend\ShopController;
use App\Http\Controllers\Frontend\ShopTagController;
use App\Http\Controllers\Frontend\CustomerController;
use App\Http\Controllers\Frontend\WishlistController;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

Auth::routes(['verify' => true]);

Route::get('/', [HomeController::class, 'index'])->name('home');
Route::get('/search', [HomeController::class, 'search'])->name('search');
Route::get('/cart', [CartController::class, 'index'])->name('cart.index');
Route::get('/shop/{slug?}', [ShopController::class, 'index'])->name('shop.index');
Route::get('/shop/tag/{slug}', [ShopTagController::class, 'index'])->name('shop.tag');
Route::get('/wishlist', [WishlistController::class, 'index'])->name('wishlist.index');
Route::get('/product/{slug}', [ProductController::class, 'show'])->name('product.show');
Route::get('/contact', [ContactController::class, 'index'])->name('contact.index');
Route::post('/contact', [ContactController::class, 'store'])->name('contact.store');
Route::get('/page/{slug}', [PageController::class, 'show'])->name('page.show');

// Login by social media [ Facebook - Twitter - Google ]
Route::get('login/{provider}', [LoginController::class, 'redirectToProvider'])->name('social_login');
Route::get('login/{provider}/callback', [LoginController::class, 'handleProviderCallback'])->name('social_login_callback');

Route::middleware(['auth:customer'])->group(function() {

    Route::prefix("customer")->group(function() {
//    Route::middleware(['verified'])->group(function() {
        Route::get('/dashboard', [CustomerController::class, 'dashboard'])->name('user.dashboard');
        Route::get('/profile', [CustomerController::class, 'profile'])->name('user.profile');
        Route::patch('/profile', [CustomerController::class, 'updateProfile'])->name('user.update_profile');
        Route::get('/profile/remove-image', [CustomerController::class, 'removeImage'])->name('user.remove_image');
        Route::get('/addresses', [CustomerController::class, 'addresses'])->name('user.addresses');
        Route::get('/orders', [CustomerController::class, 'orders'])->name('user.orders');
        Route::get('/payments', [CustomerController::class, 'payments'])->name('user.payments');
    });

    Route::middleware(['checkCart'])->group(function() {
        Route::get('/checkout', [CheckoutController::class, 'index'])->name('checkout.index');

        Route::prefix("payment")->group(function() {
            // PayPal gateway
            Route::post('/', [PaypalController::class, 'store'])->name('payment.store');
            Route::get('/{orderId}/cancelled', [PaypalController::class, 'cancelled'])->name('payment.cancelled');
            Route::get('/{orderId}/completed', [PaypalController::class, 'completed'])->name('payment.completed');
            Route::get('/webhook/{order?}/{env?}', [PaypalController::class, 'webhook'])->name('payment.webhook.ipn');

            // Tap gateway
            Route::get('/charge-request', [TapController::class, 'chargeRequest'])->name('checkout.charge_request');
            Route::get('/charge-update', [TapController::class, 'chargeUpdate'])->name('checkout.charge_update');
        });
//        require_once "payments-gateway.php";
//        Route::name("frontend.")->group(function (){
//            require_once  "payments-gateway.php";
//        });
    });

});
require_once "payments-gateway.php";

require_once "tests.php";
