<?php

use App\Http\Controllers\ProfileController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ProjectController;
use App\Http\Controllers\FractionalController;
use App\Http\Controllers\FormTemplateController;
use App\Http\Controllers\PropertyController;
use App\Http\Controllers\ImageController;
use App\Http\Controllers\PropertyTypeController;
use App\Http\Controllers\PublicFractionalController;
use App\Http\Controllers\PublicPropertyController;
use App\Http\Controllers\QuoteController;
use App\Http\Controllers\LeadController;
use App\Models\Quote;
use App\Http\Controllers\SectionController;
use App\Http\Controllers\WelcomeController;


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


Route::get('/dashboard', function () {
    return view('dashboard');
})->middleware(['auth', 'verified'])->name('dashboard');

Route::get('/propiedad/{property}', [PublicPropertyController::class, 'show'])->name('properties.public');

Route::get('/fractional/{fractional}', [PublicFractionalController::class, 'show'])->name('fractionals.public');

Route::get('/cotizacion/{slug}', function ($slug) {
    $quote = \App\Models\Quote::with([
        'property.propertyType',
        'property.fractional.section',
        'property.fractional.project.image', // si tu Project tiene relación image()
        'lead',
    ])->where('slug', $slug)->firstOrFail();

    $meses = [
        'january' => 'Enero','february' => 'Febrero','march' => 'Marzo','april' => 'Abril',
        'may' => 'Mayo','june' => 'Junio','july' => 'Julio','august' => 'Agosto',
        'september' => 'Septiembre','october' => 'Octubre','november' => 'Noviembre','december' => 'Diciembre',
    ];

    return view('quotes.public-show', compact('quote', 'meses'));
})->name('public.quotes.show');

Route::get('/projects/{project}/public', [ProjectController::class, 'public'])
    ->name('projects.public');

    // Sección pública
Route::get('/sections/public/{section}', [SectionController::class, 'public'])
     ->name('sections.public');


Route::view('/contacto', 'contact')->name('contact');


Route::post('/quote', [QuoteController::class, 'store'])->name('quote.store');

Route::middleware('auth')->group(function () {
    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
    Route::resource('/projects', ProjectController::class);
    Route::resource('/fractionals', FractionalController::class);
    Route::resource('/form-templates', FormTemplateController::class);
    Route::resource('/properties', PropertyController::class);
    Route::resource('/property-types', App\Http\Controllers\PropertyTypeController::class);
    Route::resource('/images', ImageController::class);
    Route::post('/properties/{property}/clone', [PropertyController::class, 'clone'])->name('properties.clone');
    Route::post('/property-types/{propertyType}/clone', [PropertyTypeController::class, 'clone'])->name('property-types.clone');
    Route::post('/fractionals/{fractional}/clone', [FractionalController::class, 'clone'])->name('fractionals.clone');
    Route::get('/quotes', [QuoteController::class, 'index'])->name('quotes.index');
    Route::get('/quotes/{quote}', [QuoteController::class, 'show'])->name('quotes.show');
    Route::resource('/sections', SectionController::class);
    Route::post('/fractionals/{fractional}/clone', [FractionalController::class, 'clone'])
    ->name('fractionals.clone');







});

require __DIR__.'/auth.php';
