<?php

namespace App\Traits\Utilities;

trait WithRequestNotification
{
    public function mountWithRequestNotification(): void
    {
        $notification = request()->input('notification');

        if ($notification) {
            $this->js(<<<'JS'
                const url = new URL(window.location);
                url.search = '';
                window.history.replaceState({}, '', url);
            JS);

            if (method_exists($this, 'toast')) {
                $this->toast($notification);
            }
        }
    }
}
