<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\TrackingController;
use App\Http\Controllers\ShippingRateController;
use App\Http\Controllers\LocationController;
use App\Http\Controllers\ServiceController;
use App\Http\Controllers\PromoController;
use App\Http\Controllers\PrivacyPolicyController;
use App\Http\Controllers\ContactController;
use App\Http\Controllers\AboutController;

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

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

// ABOUT
Route::get('/about', [AboutController::class, 'index'])->name('about.index');

// SERVICES
Route::get('/services', [ServiceController::class, 'index'])->name('services.index');
Route::get('/services/{service}', [ServiceController::class, 'show'])->name('services.show');

// PROMO
Route::get('/promos', [PromoController::class, 'index'])->name('promos.index');
Route::get('/promos/{promo}', [PromoController::class, 'show'])->name('promos.show');

// TRACKING AWB
Route::prefix('tracking')->name('tracking.')->group(function () {
    // Standard (Limit 20)
    Route::get('/standard', [TrackingController::class, 'indexStandard'])->name('standard');
    Route::post('/standard', [TrackingController::class, 'searchStandard'])->name('standard.search');

    // Bulk (Limit 300 / Lebih Besar)
    Route::get('/bulk', [TrackingController::class, 'indexBulk'])->name('bulk');
    Route::post('/bulk', [TrackingController::class, 'searchBulk'])->name('bulk.search');
    Route::get('/proof-images', [TrackingController::class, 'showProofImages'])->name('proof');
});

// LEGAL
Route::get('/privacy-policy', [PrivacyPolicyController::class, 'index'])->name('privacy-policy');

// CONTACT
Route::get('/contact', [ContactController::class, 'index'])->name('contact.index');

// Route untuk Search Shipping Rates
Route::get('/shipping/check', [ShippingRateController::class, 'search'])->name('shipping.check');


// Route untuk AJAX Dropdown
Route::get('/api/destinations', [LocationController::class, 'getDestinations']);
Route::get('/api/districts/{cityId}', [LocationController::class, 'getDistricts']);
Route::get('/api/villages/{districtId}', [LocationController::class, 'getVillages']);


// template export route
Route::get('/export/template', function () {
    return Excel::download(new \App\Filament\Exports\UploadPengirimanTemplate(), 'template_upload_pengiriman.xlsx');
})->name('export.template');



// ====================================================
// LEGACY REDIRECTS (Redirect URL Lama ke Laravel)
// ====================================================

// web_tracking.php -> Tracking Standard
Route::permanentRedirect('/web_tracking.php', '/tracking/standard');

// contact_us.html -> Halaman Contact
Route::permanentRedirect('/contact_us.html', '/contact');

// privacy_police.html -> Privacy Policy
// (Pastikan nama file lama beneran 'police' atau 'policy', sesuaikan aja string kirinya)
Route::permanentRedirect('/privacy_police.html', '/privacy-policy');

// customer.html -> Halaman About
Route::permanentRedirect('/customer.html', '/about');

// Maintenance Middleware for 
/* * ==========================================
 * MAINTENANCE AREA (SIAP PAKAI)
 * ==========================================
 * Jika ingin mengaktifkan maintenance khusus untuk halaman Contact atau Services,
 * Pindahkan route Route::view(...) di atas ke dalam group ini, 
 * dan pastikan middleware 'partial.maintenance' sudah didaftarkan.
 */

Route::middleware(['partial.maintenance'])->group(function () {
    // Contoh jika halaman contact lagi maintenance:
    // Route::view('/contact', 'contact.index')->name('contact');
    // Route::get('/shipping/check', [ShippingRateController::class, 'search'])->name('shipping.check');

});

