<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ClientController;
use App\Http\Controllers\MagasinController;
use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\FournisseurControlleur;

Route::get('/', function () {
    return auth()->check() ? redirect()->route('dashboard') : redirect()->route('login');
});

Route::get('/login', [LoginController::class, 'showLoginForm'])->name('login')->middleware('guest');
Route::post('/login', [LoginController::class, 'login'])->middleware('guest');
Route::post('/logout', [LoginController::class, 'logout'])->name('logout')->middleware('auth');

Route::middleware('auth')->group(function () {
    Route::get('/dashboard', fn() => view('dashboard'))->name('dashboard');
    Route::put('magasins/{id}/disabled', [MagasinController::class, 'disabledStore'])->name('magasins.disabled');
    Route::resource('magasins', MagasinController::class);
    Route::resource('clients', ClientController::class)->parameters(['clients' => 'id']);
    Route::resource('fournisseurs', FournisseurControlleur::class)->parameters(['fournisseurs' => 'id']);
    Route::resource('depenses', DepenseController::class)->parameters(['depenses' => 'id']);
});

Route::get('/produits', function () {
    return view('produits.index');
})->name('produits.index');

Route::get('/stock', function () {
    return view('stock.index');
})->name('stock.index');

Route::get('/transferts', function () {
    return view('transferts.index');
})->name('transferts.index');

Route::get('/ventes', function () {
    return view('ventes.index');
})->name('ventes.index');

Route::get('/cautions', function () {
    return view('cautions.index');
})->name('cautions.index');

Route::get('/factures', function () {
    return view('factures.index');
})->name('factures.index');

Route::get('/achats', function () {
    return view('achats.index');
})->name('achats.index');

Route::get('/depenses', function () {
    return view('depenses.index');
})->name('depenses.index');

Route::get('/mouvements', function () {
    return view('mouvements.index');
})->name('mouvements.index');

Route::get('/personnel', function () {
    return view('personnel.index');
})->name('personnel.index');

Route::get('/inventaire', function () {
    return view('inventaire.index');
})->name('inventaire.index');

Route::get('/audits', function () {
    return view('audits.index');
})->name('audits.index');

Route::get('/rapports', function () {
    return view('rapports.index');
})->name('rapports.index');