<?php

use Illuminate\Support\Facades\Route;
use TPS\Shop\Http\Controllers\AddressController;
use TPS\Shop\Http\Controllers\Registration;
use TPS\Shop\Http\Controllers\Session;
use TPS\Shop\Http\Controllers\WishlistController;

Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function () {
    /**
     * Cart merger middleware. This middleware will take care of the items
     * which are deactivated at the time of buy now functionality. If somehow
     * user redirects without completing the checkout then this will merge
     * full cart.
     *
     * If some routes are not able to merge the cart, then place the route in this
     * group.
     */
    Route::group(['middleware' => ['cart.merger']], function () {
        Route::prefix('customer')->group(function () {

            /**
             * Login routes.
             */

            Route::post('login', [Session::class, 'create'])->defaults('_config', [
                'redirect' => 'shop.home.index',
            ])->name('customer.session.create');

            /**
             * Registration routes.
             */

            Route::post('register', [Registration::class, 'create'])->name('customer.register.create');
            Route::post('send-verification', [Registration::class, 'sendCode'])->name('customer.register.send');
            Route::post('recovery', [Registration::class, 'resetPassword'])->name('customer.register.recovery');
            Route::post('reset-password', [Registration::class, 'changePassword'])->name('customer.register.reset_password');

            Route::post('verify', [Registration::class, 'verify'])->defaults('_config', [
                'redirect' => 'customer.session.index',
            ])->name('customer.register.verify');

            /**
             * Logout.
             */
            Route::delete('logout', [Session::class, 'destroy'])->defaults('_config', [
                'redirect' => 'shop.home.index',
            ])->name('customer.session.destroy');

            /**
             * Customer authenticated routes. All the below routes only be accessible
             * if customer is authenticated.
             */
            Route::group(['middleware' => ['customer']], function () {
                /**
                 * Customer account. All the below routes are related to
                 * customer account details.
                 */
                Route::prefix('account')->group(function () {
                    Route::post('profile/edit', [Registration::class, 'update'])->defaults('_config', [
                        'redirect' => 'customer.profile.edit',
                    ])->name('customer.profile.store');
                    /**
                     * Wishlist.
                     */
                    Route::get('wishlist', [WishlistController::class, 'index'])->defaults('_config', [
                        'view' => 'shop::customers.account.wishlist.wishlist',
                    ])->name('customer.wishlist.index');
                    /**
                     * Addresses.
                     */
                    Route::post('addresses/create', [AddressController::class, 'store'])->defaults('_config', [
                        'view'     => 'shop::customers.account.address.address',
                        'redirect' => 'customer.address.index',
                    ])->name('customer.address.store');
                });
            });



        });
    });
});
