<?php

namespace App\Http\Livewire;


use App\Models\ConsommationOption;
use App\Settings\GeneralSetting;
use Illuminate\Support\Collection;
use Spatie\LivewireWizard\Components\StepComponent;

class ConsommationTypeStep extends StepComponent
{
    public $consommation_option_id = null;

    public array|Collection $consommation_options = [];

    public function mount()
    {
        $this->consommation_options = ConsommationOption::get();
    }

    public function updatedConsommationOptionId($value)
    {
        $this->validate([
            'consommation_option_id' => 'required|exists:consommation_options,id',
        ]);

        session()->put('client_input.consommation_option_id', $this->consommation_option_id);

        $consommation_option = ConsommationOption::find($this->consommation_option_id);
        session()->put('client_input.dhValue', round($consommation_option->consommation_khw / app(GeneralSetting::class)->prix_khw_en_dh));
        session()->put('client_input.whValue', $consommation_option->consommation_khw);

        $this->showStep('toiture-type-step');
    }

    public function render()
    {
        return view('livewire.consommation-type-step');
    }
}
