<?php

use Illuminate\Support\Facades\Route;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\ServiceController;
use App\Http\Controllers\PortfolioController;
use App\Http\Controllers\TestimonialController;
use App\Http\Controllers\AboutController;
use App\Http\Controllers\ContactController;
use Illuminate\Support\Facades\Storage;
use App\Http\Controllers\CareerController;

// Redirect root ke locale default
Route::get('/', function () {
    return redirect(LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale()));
});

// Group routes bahasa (pakai alias middleware jika sudah terdaftar)
Route::group(
    [
        'prefix' => LaravelLocalization::setLocale(),
        'middleware' => ['localeSessionRedirect', 'localizationRedirect', 'localeViewPath']
    ],
    function () {
        Route::get('/', [HomeController::class, 'index'])->name('home');
        Route::get('/services', [ServiceController::class, 'index'])->name('services');
        Route::get('/portfolio', [PortfolioController::class, 'index'])->name('portfolio');
        Route::get('/testimonials', [TestimonialController::class, 'index'])->name('testimonials');
        Route::get('/about', [AboutController::class, 'index'])->name('about');
        Route::get('/contact', [ContactController::class, 'index'])->name('contact');
        Route::post('/contact', [ContactController::class, 'submit'])->name('contact.submit');
    }
);

Route::get('/services/image/{filename}', function ($filename) {
    $path = 'services/' . $filename;

    if (!Storage::disk('private')->exists($path)) {
        abort(404);
    }

    return response()->file(storage_path('app/private/' . $path));
})->name('services.image');


Route::get('/career', [CareerController::class, 'index'])->name('career');
Route::get('/career/{jobPosting}', [CareerController::class, 'show'])->name('career.show');
Route::post('/career/{jobPosting}/apply', [CareerController::class, 'apply'])->name('career.apply');