import { t } from '@/services/i18n';
import { setTrustedHtml, trustedHtml } from '@/utils/dom-utils';

export const SETTINGS_GEAR_SVG = `<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>`;

/**
 * Build the settings gear button. Shared between the eager `LazyUnifiedSettings`
 * proxy (event-handlers.ts) and the real `UnifiedSettings.getButton()` so the
 * markup/ARIA/SVG stay in one place — the proxy needs the button without
 * statically importing (and re-eagerizing) the UnifiedSettings chunk.
 */
export function createSettingsButton(onClick: () => void): HTMLButtonElement {
  const btn = document.createElement('button');
  btn.className = 'unified-settings-btn';
  btn.id = 'unifiedSettingsBtn';
  btn.setAttribute('aria-label', t('header.settings'));
  setTrustedHtml(btn, trustedHtml(SETTINGS_GEAR_SVG, 'legacy direct innerHTML migration'));
  btn.addEventListener('click', onClick);
  return btn;
}
