/**
 * `<toast-ui>` — auto-registers the tag on import.
 *
 * For non-side-effect class import (test isolation, tag override), use
 * the `class` subpath:
 *
 *   import { UIToast } from '@adia-ai/web-components/components/toast/class';
 *
 * @see ../../USAGE.md#registration--auto-vs-explicit
 */

import { defineIfFree } from '../../core/register.js';
import { UIToast } from './toast.class.js';

defineIfFree('toast-ui', UIToast);

/* Idempotent install of the global 'toast' CustomEvent listener.
   Same shape as the historical channel — code that posts via
   `window.dispatchEvent(new CustomEvent('toast', {detail:{…}}))`
   keeps working. Delegates to UIToast.show() → UIFeed.post(). */
if (typeof window !== 'undefined' && !window.__adiaToastListenerInstalled) {
  window.__adiaToastListenerInstalled = true;
  window.addEventListener('toast', (e) => {
    if (e?.detail && typeof e.detail === 'object') UIToast.show(e.detail);
  });
}

export { UIToast };
