<?php

namespace App\Http\Livewire;

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

class ConsommationStep extends StepComponent
{
    public int $dhValue = 0;
    public int $whValue = 0;
    public $prix_khw_en_dh;


    public function mount()
    {
        $this->prix_khw_en_dh = app(GeneralSetting::class)->prix_khw_en_dh;

        $this->dhValue = session()->get('client_input.dhValue') ?? $this->state()->currentStep()['dhValue'];
        $this->whValue = session()->get('client_input.whValue') ?? $this->state()->currentStep()['whValue'];
    }

    public function submitForm()
    {
        $this->validate([
            'dhValue' => 'required|numeric|min:1',
            'whValue' => 'required|numeric|min:1',
        ]);

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

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


    public function render()
    {
        return view('livewire.consommation-step')->layout('layouts.guest.guest');
    }
}
