<?php

namespace App\Traits;

use Flux\Flux;

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

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

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

            return;
        }

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