<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\TerbaruController;
use App\Http\Controllers\ApparelNewController;
use App\Http\Controllers\ApparelSecondController;
use App\Http\Controllers\FootwearNewController;
use App\Http\Controllers\FootwearSecondController;
use App\Http\Controllers\LoginController;
use App\Http\Controllers\DashboardController;

/*
|--------------------------------------------------------------------------
| HALAMAN PUBLIK
|--------------------------------------------------------------------------
*/
Route::get('/', [TerbaruController::class, 'index']);

// Tambahkan Rute untuk Detail Produk di bawahnya
Route::get('/beranda/{kategori}/{nama_produk}', [TerbaruController::class, 'show']);

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

Route::get('/beranda/apparel-new',    [ApparelNewController::class,    'index']);
Route::get('/beranda/apparel-second', [ApparelSecondController::class, 'index']);
Route::get('/beranda/footwear-new',   [FootwearNewController::class,   'index']);
Route::get('/beranda/footwear-second',[FootwearSecondController::class,'index']);

/*
|--------------------------------------------------------------------------
| LOGIN
|--------------------------------------------------------------------------
*/
Route::get('/login',  [LoginController::class, 'index'])->name('login');
Route::post('/login', [LoginController::class, 'authenticate']);

/*
|--------------------------------------------------------------------------
| DASHBOARD ADMIN
| — Cek session login dulu, baru panggil DashboardController
|--------------------------------------------------------------------------
*/
Route::get('/dashboard', function () {
    if (!session('is_admin')) {
        return redirect('/login')->with('error', 'Akses ditolak! Silakan login terlebih dahulu.');
    }
    return app(DashboardController::class)->index();
});

Route::get('/kelola-produk', [DashboardController::class, 'kelolaProduk']);

// Ubah dari Route::get langsung ke View, menjadi lewat Controller
Route::get('/kelola-produk/ubah-produk/{name}', [DashboardController::class, 'editProduk']);

// Route untuk Halaman Tambah Produk
Route::get('/kelola-produk/tambah-produk', [DashboardController::class, 'tambahProduk']);
// Route POST untuk memproses form tambah produk (simulasi/backend)
Route::post('/tambah-produk', [DashboardController::class, 'storeProduk']);

Route::get('/analitik-produk', [DashboardController::class, 'analitikProduk']);