<?php

namespace App\Http\Controllers;

use App\Models\Fractional;
use Illuminate\Http\Request;

class PublicFractionalController extends Controller
{
    public function show(Fractional $fractional)
    {
        $fractional->load('properties.propertyType');

        $monthKeys = [
            'january', 'february', 'march', 'april', 'may', 'june',
            'july', 'august', 'september', 'october', 'november', 'december'
        ];

        // Estructura: [property_id => [month => price]]
        $pricesByProperty = [];

        foreach ($fractional->properties as $property) {
            $prices = [];

            foreach ($monthKeys as $key) {
                $prices[$key] = $property->propertyType->{'price_' . $key};
            }

            $pricesByProperty[$property->id] = $prices;
        }

        return view('fractionals.public', [
            'fractional' => $fractional,
            'properties' => $fractional->properties,
            'pricesByProperty' => $pricesByProperty,
        ]);
    }
}
