import { describe, expect, it } from 'vitest';
import { BOT_BUTTON_ID, LOGIN_BUTTON_ID, botInfoPopup, gameLimitGuestPopup, gameLimitDurablePopup } from './nativedialogs';

describe('botInfoPopup', () => {
  it('inlines the bot handle and adds an open-bot button', () => {
    const p = botInfoPopup('Title', 'Open the bot {bot} to play.', 'erudit_bot', 'OK');
    expect(p.title).toBe('Title');
    expect(p.message).toBe('Open the bot @erudit_bot to play.');
    expect(p.buttons).toEqual([
      { id: BOT_BUTTON_ID, text: '@erudit_bot' },
      { id: 'ok', text: 'OK' },
    ]);
  });

  it('drops the token and the open-bot button when no username is known', () => {
    const p = botInfoPopup('Title', 'Open the bot {bot} to play.', '', 'OK');
    expect(p.message).toBe('Open the bot to play.');
    expect(p.buttons).toEqual([{ id: 'ok', text: 'OK' }]);
  });

  it('preserves newlines in the message', () => {
    const p = botInfoPopup('Hi', 'Welcome!\n\nUse {bot} now.', 'b', 'OK');
    expect(p.message).toBe('Welcome!\n\nUse @b now.');
  });
});

describe('gameLimitGuestPopup', () => {
  it('offers a cancel and a login button (the sign-in funnel)', () => {
    const p = gameLimitGuestPopup('More games?', 'Sign in to play more.', 'Cancel', 'Sign in');
    expect(p.title).toBe('More games?');
    expect(p.message).toBe('Sign in to play more.');
    expect(p.buttons).toEqual([
      { id: 'cancel', text: 'Cancel' },
      { id: LOGIN_BUTTON_ID, text: 'Sign in' },
    ]);
  });
});

describe('gameLimitDurablePopup', () => {
  it('is an OK-only notice', () => {
    const p = gameLimitDurablePopup('Game limit', 'Finish a current game first.', 'OK');
    expect(p.buttons).toEqual([{ id: 'ok', text: 'OK' }]);
  });
});
