import { NotificationItem } from '../../models/notification.model';
import { notificationIcon, notificationLabel, notificationTarget } from './notification-presentation';

function item(overrides: Partial<NotificationItem>): NotificationItem {
  return {
    id: 1,
    event: 'player_creation',
    actorUserId: 9,
    payload: {},
    read: false,
    createdAt: '2026-08-04T10:00:00.000Z',
    ...overrides,
  };
}

describe('notification-presentation', () => {
  it('describes an active-state change', () => {
    expect(
      notificationLabel(item({ event: 'player_active_update', payload: { playerName: 'Ada Lovelace', active: false } })),
    ).toBe('Ada Lovelace wurde deaktiviert');
    expect(
      notificationLabel(item({ event: 'player_active_update', payload: { playerName: 'Ada Lovelace', active: true } })),
    ).toBe('Ada Lovelace wurde aktiviert');
  });

  it('describes a role change', () => {
    expect(
      notificationLabel(item({ event: 'player_team_role_update', payload: { playerName: 'Ada Lovelace' } })),
    ).toBe('Team-Rolle von Ada Lovelace wurde geändert');
  });

  it('describes a new player', () => {
    expect(
      notificationLabel(item({ event: 'player_creation', payload: { playerName: 'Ada Lovelace' } })),
    ).toBe('Ada Lovelace wurde zum Team hinzugefügt');
  });

  it('describes share-link events', () => {
    expect(notificationLabel(item({ event: 'public_access_enabled' }))).toBe('Der Freigabelink wurde aktiviert');
    expect(notificationLabel(item({ event: 'public_access_rotated' }))).toBe('Der Freigabelink wurde erneuert');
  });

  it('describes a new invite link', () => {
    expect(notificationLabel(item({ event: 'user_invite_link_create' }))).toBe(
      'Ein neuer Einladungslink wurde erstellt',
    );
  });

  it('maps each event to an icon', () => {
    expect(notificationIcon('player_active_update')).toBe('person');
    expect(notificationIcon('player_team_role_update')).toBe('badge');
    expect(notificationIcon('player_creation')).toBe('person_add');
    expect(notificationIcon('public_access_enabled')).toBe('link');
    expect(notificationIcon('public_access_rotated')).toBe('link');
    expect(notificationIcon('user_invite_link_create')).toBe('mail');
  });

  it('routes player-related notifications to the member detail page', () => {
    expect(notificationTarget(item({ event: 'player_creation', payload: { playerId: 21 } }), 5)).toEqual([
      '/team', 5, 'members', 21,
    ]);
  });

  it('routes share-link notifications to the public-access settings page', () => {
    expect(notificationTarget(item({ event: 'public_access_rotated' }), 5)).toEqual([
      '/team', 5, 'more', 'public-access',
    ]);
  });

  it('routes invite-link notifications to the invite page', () => {
    expect(notificationTarget(item({ event: 'user_invite_link_create' }), 5)).toEqual([
      '/team', 5, 'more', 'invite',
    ]);
  });
});
