<?php

use Illuminate\Support\Facades\Route;

use AkkiIo\LaravelGoogleAnalytics\Facades\LaravelGoogleAnalytics;
use AkkiIo\LaravelGoogleAnalytics\Period;
use Themes\Pro\modunawa\app\Http\Controllers\Auth\CompanySignupController;
use Themes\Pro\modunawa\app\Http\Controllers\Auth\FindMemberIdController;
use Themes\Pro\modunawa\app\Http\Controllers\Auth\FindMemberIdVerifyController;
use Themes\Pro\modunawa\app\Http\Controllers\Auth\FindMemberPwVerifyController;
use Themes\Pro\modunawa\app\Http\Controllers\Auth\FindMemberPwVerifyinputController;
use Themes\Pro\modunawa\app\Http\Controllers\Auth\MemberWithdrawalController;
use Themes\Pro\modunawa\app\Http\Controllers\Auth\PasswordChangeController;
use Themes\Pro\modunawa\app\Http\Controllers\EFinanceController;
use Themes\Pro\modunawa\app\Http\Controllers\Etc\OneToOneController;
use Themes\Pro\modunawa\app\Http\Controllers\IndexController;
use Themes\Pro\modunawa\app\Http\Controllers\Auth\LoginController;
use Themes\Pro\modunawa\app\Http\Controllers\Auth\MemberSignupVerifyController;
use Themes\Pro\modunawa\app\Http\Controllers\Auth\SignupController;
use Themes\Pro\modunawa\app\Http\Controllers\MyPage\EventController;
use Themes\Pro\modunawa\app\Http\Controllers\MyPage\MemberEditController;
use Themes\Pro\modunawa\app\Http\Controllers\MyPage\NoticeController;
use Themes\Pro\modunawa\app\Http\Controllers\MyPage\OrderController;
use Themes\Pro\modunawa\app\Http\Controllers\MyPage\QnaController;
use Themes\Pro\modunawa\app\Http\Controllers\PolicyController;
use Themes\Pro\modunawa\app\Http\Controllers\PrivacyController;
use Themes\Pro\modunawa\app\Http\Controllers\RefundController;
use Themes\Pro\modunawa\app\Http\Controllers\Shop\AddressAddController;
use Themes\Pro\modunawa\app\Http\Controllers\Shop\CartController;
use Themes\Pro\modunawa\app\Http\Controllers\Shop\CheckoutController;
use Themes\Pro\modunawa\app\Http\Controllers\Shop\CheckoutOkController;
use Themes\Pro\modunawa\app\Http\Controllers\Shop\ContactAddController;
use Themes\Pro\modunawa\app\Http\Controllers\Shop\ItemController;
use Themes\Pro\modunawa\app\Http\Controllers\Shop\WalletAddController;
use Themes\Pro\modunawa\app\Http\Controllers\Shop\WalletBalanceController;
use Themes\Pro\modunawa\app\Http\Controllers\Shop\WalletSendController;
use Themes\Pro\modunawa\app\Http\Controllers\Shop\WishController;

Route::get('/test', function () {
    // build a query using the `get()` method
    $a = LaravelGoogleAnalytics::getTotalUsers(Period::days(1));
    dd($a);
});

Route::middleware('check.gate.token')->group(function () {
    Route::get('/', [IndexController::class, 'index'])->name('index');

    Route::get('/item-list', function() {
        return view('views.shop.item-list');
    })->name('item-list');

    Route::get('/item-gallery/{igroupCode}', [ItemController::class, 'index'])->name('item-gallery');

    Route::get('/item-details/{id}', [ItemController::class, 'show'])->name('item-details');

    Route::get('/credit-item-list', function () {
        return view('views.shop.credit-item-list');
    })->name('credit-item-list');

    Route::get('/credit-item-detail', function () {
        return view('views.shop.credit-item-detail');
    })->name('credit-item-detail');

    Route::get('/cart', function() {
        return view('views.shop.cart');
    })->name('cart');

    Route::prefix('my-page')->name('my-page.')->group(function () {

        Route::get('/notice-list', [NoticeController::class, 'list'])->name('notice.list');
        Route::get('/notice-details/{id}', [NoticeController::class, 'show'])->name('notice.show');

        Route::get('/ticket-list', function () {
            return view('views.my-page.ticket-list');
        })->name('ticket-list');

        Route::get('/credit-io-list', function () {
            return view('views.my-page.credit-io-list');
        })->name('credit-io-list');

        Route::get('/event-list', [EventController::class, 'list'])->name('event.list');
        Route::get('/event-details/{id}', [EventController::class, 'show'])->name('event.show');

        Route::get('/qna-list', function () {
            return view('views.my-page.qna-list');
        })->name('qna-list');

    });

    Route::get('/policy-list', [PolicyController::class, 'index'])->name('policy.index');
    Route::get('/policy-detail/{unique}', [PolicyController::class, 'show'])->name('policy.show');

    Route::get('/privacy-list', [PrivacyController::class, 'index'])->name('privacy.index');
    Route::get('/privacy-detail/{unique}', [PrivacyController::class, 'show'])->name('privacy.show');

    Route::get('/e-finance-list', [EFinanceController::class, 'index'])->name('e-finance.index');
    Route::get('/e-finance-detail/{unique}', [EFinanceController::class, 'show'])->name('e-finance.show');

    Route::get('/refund-list', [RefundController::class, 'index'])->name('refund.index');
    Route::get('/refund-detail/{unique}', [RefundController::class, 'show'])->name('refund.show');

    Route::get('/member-go-email', function() {
        return view('views.auth.member-go-email');
    })->name('member-go-email');

    Route::get('/member-signup', [SignupController::class, 'index'])->name('member-signup.index');
    Route::post('/member-signup', [SignupController::class, 'store'])->name('member-signup.store');
    Route::get('/confirm', [SignupController::class, 'confirm'])->name('confirm');

    Route::get('/member-verify-ok', function() {
        return view('views.auth.member-verify-ok');
    })->name('member-verify-ok');

    Route::get('/member-verify-resend', function() {
        return view('views.auth.member-verify-resend');
    })->name('member-verify-resend');

    Route::post('/member-verify-resend', [SignupController::class, 'activateCodeResend'])->name('member-verify-resend');

    Route::get('/password-reset', function() {
        return view('views.auth.password-reset');
    })->name('password-reset');

    Route::get('/member-withdraw-cancel', function() {
        return view('views.auth.member-withdraw-cancel');
    })->name('member-withdraw-cancel');

    Route::get('/member-sso-login', function() {
        return view('views.auth.member-sso-login');
    })->name('member-sso-login');

    Route::get('/member-signup-agree', function() {
        return view('views.auth.member-signup-agree');
    })->name('member-signup-agree');

    Route::get('/member-company-signup', [CompanySignupController::class, 'index'])->name('member-company-signup.index');
    Route::post('/member-company-signup', [CompanySignupController::class, 'store'])->name('member-company-signup.store');

    Route::get('/member-signup-branch', function() {
        return view('views.auth.member-signup-branch');
    })->name('member-signup-branch');

    Route::get('/member-signup-verify', [MemberSignupVerifyController::class, 'index'])->name('member-signup-verify.index');
    Route::post('/member-signup-verify', [MemberSignupVerifyController::class, 'store'])->name('member-signup-verify.store');
    Route::post('/member-signup-verify-send', [MemberSignupVerifyController::class, 'sendCert'])->name('member-signup-verify.send');

    Route::get('/member-activate-failed', function() {
        return view('views.auth.member-activate-failed');
    })->name('member-activate-failed');

    Route::get('/password-reset-code-failed', function() {
        return view('views.auth.password-reset-code-failed');
    })->name('password-reset-code-failed');

    Route::get('/find-member-id-verify', [FindMemberIdVerifyController:: class, 'index'])->name('find-member-id-verify.index');
    Route::post('/find-member-id-verify', [FindMemberIdVerifyController:: class, 'store'])->name('find-member-id-verify.store');

    Route::get('/find-member-id', [FindMemberIdController::class, 'index'])->name('find-member-id.index');

    Route::get('/find-member-pw-memcheck', function() {
        return view('views.auth.find-member-pw-memcheck');
    })->name('find-member-pw-memcheck.index');

    Route::get('/find-member-pw-verify', [FindMemberPwVerifyController::class, 'index'])->name('find-member-pw-verify.index');
    Route::post('/find-member-pw-verify', [FindMemberPwVerifyController::class, 'store'])->name('find-member-pw-verify.store');

    Route::get('/find-member-pw-verifyinput', [FindMemberPwVerifyinputController::class, 'emailVerifyinput'])->name('find-member-pw-verifyinput');

    Route::get('/paq', [QnaController::class, 'list'])->name('paq');

    Route::get('/contact-us', function() {
        return view('views.etc.contact-us');
    })->name('contact-us');

    Route::get('/password-change', [PasswordChangeController::class, 'index'])->name('password-change.index');
    Route::post('/password-change', [PasswordChangeController::class, 'store'])->name('password-change.store');

    Route::middleware('check.pro.member')->group(function () {
        Route::get('/member-withdrawal', [MemberWithdrawalController::class, 'index'])->name('member-withdrawal.index');
        Route::post('/member-withdrawal', [MemberWithdrawalController::class, 'store'])->name('member-withdrawal.store');

        Route::post('/cart', [CartController::class, 'store'])->name('cart.store');

        Route::get('/wish-list', [WishController::class, 'index'])->name('wish-list.index');
        Route::post('/wish-list', [WishController::class, 'favorite'])->name('wish-list.favorite');
        Route::delete('/wish-list', [WishController::class, 'destroy'])->name('wish-list.destroy');

        Route::get('/checkout', [CheckOutCOntroller::class, 'index'])->name('checkout.index');
        Route::post('/checkout', [CheckOutCOntroller::class, 'store'])->name('checkout.store');

        Route::get('/checkout-ok', [CheckoutOkController::class, 'index'])->name('checkout-ok');

        Route::get('/checkout-failed', function() {
            return view('views.shop.checkout-failed');
        })->name('checkout-failed');

        Route::prefix('my-page')->name('my-page.')->group(function () {
            Route::get('/member-edit', [MemberEditController::class, 'index'])->name('member-edit.index');
            Route::get('/member-edit/{id}', [MemberEditController::class, 'show'])->name('member-edit.show');
            Route::post('/member-edit/{id}', [MemberEditController::class, 'update'])->name('member-edit.update');

            Route::get('/order-list', [OrderController::class, 'list'])->name('order-list');
        });

        Route::post('/wallet-add', [WalletAddController::class, 'store'])->name('wallet.store');

        Route::get('/contact-add', [ContactAddController::class, 'index'])->name('contact.index');
        Route::post('/contact-add', [ContactAddController::class, 'store'])->name('contact.store');
        Route::get('/contact-add/{id}', [ContactAddController::class, 'show'])->name('contact.show');
        Route::post('/contact-add/{id}', [ContactAddController::class, 'update'])->name('contact.update');
        Route::delete('/contact-add/{id}', [ContactAddController::class, 'destroy'])->name('contact.destroy');

        Route::get('/address-add', [AddressAddController::class, 'index'])->name('address.index');
        Route::post('/address-add', [AddressAddController::class, 'store'])->name('address.store');
        Route::get('/address-add/{id}', [AddressAddController::class, 'show'])->name('address.show');
        Route::post('/address-add/{id}', [AddressAddController::class, 'update'])->name('address.update');
        Route::delete('/address-add/{id}', [AddressAddController::class, 'destroy'])->name('address.destroy');

        Route::get('/wallet-balance', [WalletBalanceController::class, 'index'])->name('wallet-balance.index');
        Route::post('/wallet-balance', [WalletBalanceController::class, 'result'])->name('wallet-balance.result');

        Route::get('/wallet-send', [WalletSendController::class, 'index'])->name('wallet-send.index');
        Route::post('/wallet-send', [WalletSendController::class, 'result'])->name('wallet-send.result');

        Route::get('/1to1-list', [OneToOneController::class, 'list'])->name('1to1.list');
        Route::get('/1to1-details/{id}', [OneToOneController::class, 'show'])->name('1to1.show');
        Route::get('/1to1-form', function() {
            return view('views.etc.1to1-form');
        })->name('1to1.form');
        Route::post('/1to1-form', [OneToOneController::class, 'store'])->name('1to1.store');
    });

    Route::group(['middleware' => 'check.pro.guest'], function () {

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

    Route::post('/member-login', [LoginController::class, 'store'])->name('member-login.store');

});

Route::get('/member-logout', function() {
    session()->forget('member');
    session()->forget('GateToken');
    session()->forget('locale');
    session()->forget('wallet');

    return redirect()->to('/');
})->name('member-logout');
