<?php

namespace App\Livewire\Concerns;

trait FlashesAppToast
{
    protected function flashAppToast(string $message, string $variant = 'success'): void
    {
        $detail = json_encode(
            ['message' => $message, 'variant' => $variant],
            JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_THROW_ON_ERROR
        );
        $this->js("window.dispatchEvent(new CustomEvent('app-toast', { detail: {$detail} }))");
    }
}
