import { mountToolbar, type WidgetConfig } from './toolbar';

(function () {
  const cfg = (window as Record<string, unknown>).accessmateWidgetConfig as WidgetConfig | undefined;

  const config: WidgetConfig = cfg ?? {
    color:    '#7c6aff',
    position: 'bottom-right',
    features: ['font', 'contrast', 'dyslexia'],
  };

  if (config.enabled === false) return;

  const POSITIONS: Record<string, string> = {
    'bottom-right': 'bottom:20px;right:20px',
    'bottom-left':  'bottom:20px;left:20px',
    'top-right':    'top:20px;right:20px',
    'top-left':     'top:20px;left:20px',
  };

  const host   = document.createElement('div');
  host.id      = 'accessmate-widget-host';
  host.style.cssText = `position:fixed;z-index:2147483647;${POSITIONS[config.position] ?? POSITIONS['bottom-right']}`;

  const shadow = host.attachShadow({ mode: 'open' });
  document.body.appendChild(host);

  mountToolbar(shadow, config);
})();
