<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Admin\DashboardController as AdminDashboardController;
use App\Http\Controllers\Admin\StabileController;
use App\Http\Controllers\Admin\UnitaImmobiliareController;

/*
|--------------------------------------------------------------------------
| Admin Routes - Versione Semplificata
|--------------------------------------------------------------------------
*/

Route::group(['prefix' => 'admin', 'as' => 'admin.', 'middleware' => ['auth']], function () {

    // Dashboard
    Route::get('/', [AdminDashboardController::class, 'index'])->name('dashboard');
    Route::get('/dashboard', [AdminDashboardController::class, 'index'])->name('dashboard.index');

    // Stabili (solo route essenziali)
    Route::group(['prefix' => 'stabili', 'as' => 'stabili.'], function () {
        Route::get('/', [StabileController::class, 'index'])->name('index');
        Route::get('/create', [StabileController::class, 'create'])->name('create');
        Route::post('/', [StabileController::class, 'store'])->name('store');
        Route::get('/{stabile}', [StabileController::class, 'show'])->name('show');
        Route::get('/{stabile}/edit', [StabileController::class, 'edit'])->name('edit');
        Route::put('/{stabile}', [StabileController::class, 'update'])->name('update');
        Route::delete('/{stabile}', [StabileController::class, 'destroy'])->name('destroy');

        // AJAX Routes per tab dinamiche
        Route::get('/{stabile}/unita-immobiliari', [StabileController::class, 'getUnitaImmobiliari'])->name('unita_immobiliari');
    });

    // Unità Immobiliari
    Route::group(['prefix' => 'unita_immobiliari', 'as' => 'unita_immobiliari.'], function () {
        Route::get('/', [UnitaImmobiliareController::class, 'index'])->name('index');
        Route::get('/create', [UnitaImmobiliareController::class, 'create'])->name('create');
        Route::post('/', [UnitaImmobiliareController::class, 'store'])->name('store');
        Route::get('/{unitaImmobiliare}', [UnitaImmobiliareController::class, 'show'])->name('show');
        Route::get('/{unitaImmobiliare}/edit', [UnitaImmobiliareController::class, 'edit'])->name('edit');
        Route::put('/{unitaImmobiliare}', [UnitaImmobiliareController::class, 'update'])->name('update');
        Route::delete('/{unitaImmobiliare}', [UnitaImmobiliareController::class, 'destroy'])->name('destroy');
    });
});
