import * as scene from '../../../core/scene.js';
import * as bus from '../../../core/bus.js';
import * as audio from '../../../core/audio.js';
import { t } from '../../../core/i18n.js';
import { emoji } from '../../../core/theme.js';

export function mountResult(el, params) {
  const { result } = params;
  const isWin = result === 'win';

  el.innerHTML = `
    <div style="display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;gap:var(--s-6);padding:var(--s-6);">
      <div style="font-size:64px;animation:float 2s ease-in-out infinite;">${isWin ? emoji('trophy', '🏆', 64) : emoji('skull', '💀', 64)}</div>
      <div style="font-size:28px;font-weight:800;color:${isWin ? 'var(--win)' : 'var(--loss)'};">${isWin ? t('game.you_win') : t('game.you_lose')}</div>
      <div style="display:flex;gap:var(--s-3);margin-top:var(--s-6);">
        <button class="btn btn-primary" id="btn-again">${t('game.rematch')}</button>
        <button class="btn btn-secondary" id="btn-back">${t('game.back')}</button>
      </div>
    </div>
  `;

  el.querySelector('#btn-again').addEventListener('click', () => {
    audio.play('click');
    scene.replace('ludo-game', { mode: 'bot' });
  });
  el.querySelector('#btn-back').addEventListener('click', () => {
    audio.play('click');
    bus.emit('navigate', { world: 'play', scene: 'play-table' });
  });
}
