<?php

namespace App\Traits\Components;

use Flux\Flux;

trait WithCloseModal
{
    public function closeModal(string $modalName, ?bool $isCloseAll = false): void
    {
        $this->resetErrorBag();
        $this->resetValidation();

        if (isset($this->form)) {
            $this->reset('form');
        }

        if ($isCloseAll) {
            Flux::modals()->close();

            return;
        }

        Flux::modal($modalName)->close();
    }
}
