<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PaymentCallbackController;
use App\Http\Controllers\FashionController;
use App\Http\Controllers\CareController;
use App\Http\Controllers\HomeController;

use App\Http\Controllers\Admin\LoginController;
use App\Http\Controllers\Admin\RegisterController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\AdminFashionController;
use App\Http\Controllers\Admin\AdminFashionDetailsController;
use App\Http\Controllers\Admin\AdminCareController;
use App\Http\Controllers\Admin\AdminCareDetailsController;
use App\Http\Controllers\Admin\OrderController;
use App\Http\Controllers\Admin\OrderItemController;
use App\Http\Controllers\Admin\AdminCleanController;
use App\Http\Controllers\Admin\CustomerController;
use App\Http\Controllers\Admin\BookingController;
use App\Http\Controllers\Admin\BookingItemsController;
use App\Http\Controllers\Admin\BillingController;
use App\Http\Controllers\Admin\BillingItemsController;
//use App\Http\Controllers\Admin\InvoiceController;
use App\Http\Controllers\Admin\ShippingController;
use App\Http\Controllers\Admin\CustomBillingController;
use App\Http\Controllers\Admin\CustomBillingItemsController;
use App\Http\Controllers\Admin\UserController;
use App\Http\Controllers\Member\MemberLoginController;
use App\Http\Controllers\Member\MemberRegisterController;

/*
|--------------------------------------------------------------------------
| 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::domain('fashion.by-arsolution.com')->group(function() 
{
    Route::controller(FashionController::class)->group(function(){
        Route::get('/','index');
        Route::get('/product-data','productData');
        Route::get('/province-data','provinceData');
        Route::post('/place-order','placeOrder');
        Route::post('/place-cod','placeCod');
        Route::get('payments/finish','paymentFinish');
        Route::get('payments/unfinish','paymentUnfinish');
        Route::get('payments/error','paymentError');
        Route::get('fashion-sitemap',function(){
            return view('fashion-sitemap');
        });
    });
    
    Route::post('payments/midtrans-notification', [PaymentCallbackController::class, 'receive']);
});

Route::domain('admin.by-arsolution.com')->group(function() 
{
    Route::view('/','admin.login',['title'=>'Admin Login']);

    //Route::get('/register', [RegisterController::class, 'create'])->name('register');
    //Route::post('/register', [RegisterController::class, 'store'])->name('register');
    Route::get('/login',[LoginController::class,'login'])->name('login');
    Route::post('/login',[LoginController::class,'authenticate'])->name('login');

    Route::post('/logout', function () 
    {
        auth()->logout();
        request()->session()->invalidate();
        request()->session()->regenerateToken();
        return redirect('/');
    })->name('logout')->middleware('auth');

    
    Route::middleware('auth')->group(function()
    {
        Route::get('/dashboard',[DashboardController::class, 'index'])->name('dashboard');
        
        Route::controller(AdminFashionController::class)->group(function(){
            Route::get('admin-fashion','index');
            Route::get('admin-fashion/{id}','show');
            Route::post('admin-fashion','store');
            Route::put('admin-fashion','update');
            Route::delete('admin-fashion','destroy');
        });
        
        Route::controller(AdminFashionDetailsController::class)->group(function(){
            Route::get('/admin-fashion-details','index');
            Route::get('/admin-fashion-details/{id}','show');
            Route::post('/admin-fashion-details','store');
            Route::put('/admin-fashion-details','update');
            Route::delete('/admin-fashion-details','destroy');
        });
        
        Route::controller(AdminCareController::class)->group(function(){
            Route::get('/admin-care','index');
            Route::get('/admin-care/{id}','show');
            Route::post('/admin-care','store');
            Route::delete('/admin-care','destroy');
            Route::get('/admin-care-get-files','getFiles');
        });
            
        Route::controller(AdminCareDetailsController::class)->group(function(){
            Route::get('/admin-care-items','index');
            Route::get('/admin-care-items/{id}','show');
            Route::post('/admin-care-items','store');
            Route::delete('/admin-care-items','destroy');
        });
    
        Route::controller(OrderController::class)->group(function(){
            Route::get('/order','index');
            Route::get('/order/{id}','show');
            Route::put('/order','update');
        });
            
        Route::controller(OrderItemController::class)->group(function(){
            Route::get('order-items','index');
            Route::get('shipping-label','createLabel');
            Route::get('shipping-waybill','createWaybill');
            Route::get('shipping-invoice','createInvoice');
        });
        
        Route::controller(AdminCleanController::class)->group(function(){
            Route::get('/admin-clean','index');
            Route::get('/admin-clean/{id}','edit')->name('clean.edit');
            Route::post('/admin-clean','modify');
            Route::get('/admin-clean-create','create');
            Route::delete('/admin-clean','destroy');
        });
        
        Route::controller(CustomerController::class)->group(function(){
            Route::get('/customer','index');
            Route::post('/customer','store');
            Route::get('/customer-data','getCustomer');
            Route::delete('/customer','delete');
        });
        
        Route::controller(BookingController::class)->group(function(){
            Route::get('/booking','index');
            Route::post('/booking','insert');
            Route::get('/booking-create','create');
            Route::get('/booking-show','show');
            Route::get('/booking-form','form');
            
            Route::post('/booking-delete','delete');
            Route::get('/booking-edit','edit');
            Route::post('/booking-approve','approve');
            Route::post('/booking-insert-web', 'insertWeb');
            Route::post('/booking-save-customer','saveCustomer');
            Route::get('/booking-billing','createBilling');
        });

        Route::controller(BookingItemsController::class)->group(function(){
            Route::get('/booking-items','index');
            Route::post('/booking-items','insert');
            Route::get('/booking-item-create','create');
            Route::post('/booking-item-delete','delete');
        });

        Route::controller(BillingController::class)->group(function(){
            Route::get('/billing','index');
            Route::get('/billing-create','create');
            Route::post('/billing-insert','insert');
            Route::post('/billing-delete','delete');
            Route::get('/billing-edit','edit');
            Route::post('/billing-approve','approve');
            Route::post('/billing-item-discount','discountSave');
            
            Route::get('/sales-reporting','salesReporting');
            Route::get('/billing-invoice','createInvoice');            

        });
        
        Route::controller(BillingItemsController::class)->group(function(){
            Route::get('/billing-items','index');
            //Route::get('/billing-item-create','create');
            Route::post('/billing-items','insert');
            Route::delete('/billing-items','delete');
            Route::get('/billing-item-edit','edit');
            //Route::get('/billing-item-discount','discount');
            //Route::post('/billing-item-discount','discountSave');
        });

        Route::controller(ShippingController::class)->group(function(){
            Route::get('/shipping-cost','index');
            Route::get('/districts-data','getDistricts');
            Route::post('/shipping-save','store');
        });

        Route::controller(CustomBillingController::class)->group(function(){
            Route::get('/custom-billing','index');
            Route::post('/custom-billing','insert');
            Route::post('/custom-billing-discount','discountSave');
            Route::get('/custom-billing-invoice','createInvoice');
            Route::post('/custom-billing-delete','delete');
            Route::get('/custom-livesearch','searchCustomer');
        });

        Route::controller(CustomBillingItemsController::class)->group(function(){
            Route::get('/custom-billing-items','index');
            Route::post('/custom-billing-items','insert');
            Route::delete('/custom-billing-items','delete');
        });
        
        Route::controller(UserController::class)->group(function(){
            Route::get('/user','index');
            Route::get('/user-data','show');
            Route::get('/user-generate','generate');
        });
        
        
        //Route::get('/invoice',[InvoiceController::class,'index']);

        Route::get('/accounting',function(){
            return view('admin/accounting');
        });

    });
});

Route::domain('care.by-arsolution.com')->group(function() 
{
    Route::controller(CareController::class)->group(function(){
        Route::get('/','index');
        Route::get('/product-data','productData');
        Route::get('/fragrance-data','fragranceData');
        Route::get('/province-data','provinceData');
        Route::get('/specifications','specifications');
        Route::get('/product-item','getItem');
        Route::post('/checkout-process','checkout');
    
        Route::post('/place-order','placeOrder');
        Route::post('/place-cod','placeCod');
        Route::post('/invoice','invoice');
        Route::post('/chat-log','visitorChatLog');
        Route::post('/referral-log','referralLog');

        Route::get('/test','test');
        //Route::get('/test-mail/{recipient}','sendMessage');
    });
});

Route::domain('store.by-arsolution.com')->group(function() 
{
    Route::get('/',function(){
        return view('store/index');
    });
});

//Route::domain('by-arsolution.com')->group(function() {
    Route::get('/', function(){ return view('corporate.ar_care'); });
    Route::get('/ar-clean', function(){ return view('corporate/ar_clean'); });
    //Route::get('/ar-care', function(){ return view('corporate/ar_care'); });
    Route::get('/ar-care-form', function(){ return view('corporate/ar_care_form'); });
    Route::get('/ar-fashion', function(){ return redirect('https://fashion.by-arsolution.com'); });
    Route::get('/gallery',function(){ return view('corporate/gallery'); });
    Route::post('/home-chat-log',[HomeController::class,'visitorChatLog']);
    
    Route::get('/testimoni',function(){ return view('corporate/testimoni'); });
        Route::get('/sitemap',function(){
            return view('sitemap');
    });
//});


//Untested
Route::get('/member-register', [MemberRegisterController::class, 'create'])->name('member.register');
Route::post('/member-register', [MemberRegisterController::class, 'store'])->name('member.register');
Route::get('/member',[MemberLoginController::class,'login'])->name('member.login');
Route::post('/member',[MemberLoginController::class,'authenticate'])->name('member.login');

Route::post('/member-logout', function () {
    auth()->logout();
    request()->session()->invalidate();
    request()->session()->regenerateToken();
    return redirect('/');
})->name('member.logout')->middleware('auth:member');

Route::prefix('member')->middleware('auth:member')->group(function () {
    // Member-only routes
    Route::get('/dashboard',[MemberLoginController::class,'dashboard'])->name('member.dashboard');
});

