<?php

use App\Http\Controllers\Auth\AddressController;
use App\Http\Controllers\Auth\LoginEmailController;
use App\Http\Controllers\Auth\LoginWaController;
use App\Http\Controllers\Auth\RegisterController;
use App\Http\Controllers\HomeController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\RoutingController;
use App\Http\Controllers\LocationController;
use App\Http\Controllers\LocaleController;
use App\Http\Controllers\ProductController;
use App\Http\Controllers\SearchController;
use App\Http\Controllers\ComponentController;
use App\Http\Controllers\Auth\ProfileController;

Route::group(['prefix' => '/dummy'], function () {
    Route::get('', [RoutingController::class, 'index'])->name('root');
    Route::get('{first}/{second}/{third}', [RoutingController::class, 'thirdLevel'])->name('third');
    Route::get('{first}/{second}', [RoutingController::class, 'secondLevel'])->name('second');
    Route::get('{any}', [RoutingController::class, 'root'])->name('any');
    
});

// Location selection route
Route::post('/location/select', [LocationController::class, 'select'])->name('location.select');

// Language switching route
Route::post('/locale/switch', [LocaleController::class, 'switch'])->name('locale.switch');

Route::get('/', [HomeController::class, 'index'])->name('home');

Route::get('/products',[ProductController::class, 'index'])->name('product.index');
Route::get('/products/ajax',[ProductController::class, 'ajax'])->name('product.ajax');
Route::get('/products/ajax/highlights',[ProductController::class, 'highlights'])->name('product.ajax.highlights');
Route::get('/products/ajax/brands',[ProductController::class, 'brands'])->name('product.ajax.brands');
Route::get('/products/ajax/categories',[ProductController::class, 'categories'])->name('product.ajax.categories');
Route::get('/products/ajax/genders',[ProductController::class, 'genders'])->name('product.ajax.genders');
Route::get('/products/ajax/announcements',[ProductController::class, 'announcements'])->name('product.ajax.announcements');
Route::get('/product/{slug}',[ProductController::class, 'detail'])->name('product.detail');

// Search routes
Route::get('/search', [SearchController::class, 'search'])->name('search.ajax');

// Component loading routes
Route::get('/components/{component}', [ComponentController::class, 'load'])->name('component.load');

Route::get('/register', [RegisterController::class, 'index'])->name('register');
Route::post('/register', [RegisterController::class, 'register'])->name('register');

Route::get('/login', [LoginWaController::class, 'index'])->name('login');
Route::group(['prefix' => '/login/phone'], function () {
    Route::get('/', [LoginWaController::class, 'index'])->name('login-phone');
    Route::post('/otp', [LoginWaController::class,'otp'])->name('login-phone.otp');
    Route::get('/otp/{identity}', [LoginWaController::class, 'otpView'])->name('login-phone.otp.view');
    Route::post('/verify', [LoginWaController::class, 'verify'])->name('login-phone.verify');
});

Route::group(['prefix' => '/login/email'], function () {
    Route::get('/', [LoginEmailController::class, 'index'])->name('login-email');
    Route::post('/otp', [LoginEmailController::class, 'otp'])->name('login-email.otp');
    Route::get('/otp/{identity}', [LoginEmailController::class, 'otpView'])->name('login-email.otp.view');
    Route::post('/verify', [LoginEmailController::class, 'verify'])->name('login-email.verify');
});

// Google OAuth routes
Route::group(['prefix' => '/login/google'], function () {
    Route::get('/', [App\Http\Controllers\Auth\GoogleController::class, 'redirectToGoogle'])->name('login.google');
    Route::get('/callback', [App\Http\Controllers\Auth\GoogleController::class, 'handleGoogleCallback'])->name('login.google.callback');
});

Route::get('/profile', [ProfileController::class, 'index'])->name('profile');
Route::post('/profile', [ProfileController::class, 'update'])->name('profile.update');
Route::put('/profile/password', [ProfileController::class, 'updatePassword'])->name('profile.password.update');


Route::get('/addresses', [AddressController::class, 'index'])->name('addresses');
Route::get('/addresses/provinces', [AddressController::class, 'provinces'])->name('addresses.provinces');
Route::get('/addresses/cities/{provinceId}', [AddressController::class, 'cities'])->name('addresses.cities');
Route::get('/addresses/districts/{provinceId}', [AddressController::class, 'districts'])->name('addresses.districts');
Route::get('/addresses/villages/{districtId}', [AddressController::class, 'villages'])->name('addresses.villages');
