/**
 * Collaborator List Component Tests
 */

import { describe, it, expect } from 'vitest';
import { CollaboratorList } from './collaborator-list';
import { RemoteUser, CursorPosition } from '../../lib/collaboration/presence';

describe('CollaboratorList', () => {
  const mockUsers = new Map<string, RemoteUser>();

  const aliceCursor: CursorPosition = {
    userId: 'user-1',
    userName: 'Alice',
    position: 120,
    color: '#ef4444',
    lastActive: new Date(),
  };

  const bobCursor: CursorPosition = {
    userId: 'user-2',
    userName: 'Bob',
    position: 250,
    color: '#3b82f6',
    lastActive: new Date(),
  };

  mockUsers.set('user-1', {
    userId: 'user-1',
    userName: 'Alice',
    cursor: aliceCursor,
    isEditing: true,
    lastActive: new Date(),
  });

  mockUsers.set('user-2', {
    userId: 'user-2',
    userName: 'Bob',
    cursor: bobCursor,
    isEditing: false,
    lastActive: new Date(),
  });

  mockUsers.set('user-3', {
    userId: 'user-3',
    userName: 'Charlie',
    isEditing: false,
    lastActive: new Date(Date.now() - 7200000),
  });

  it('is a valid SolidJS component', () => {
    expect(typeof CollaboratorList).toBe('function');
  });

  it('accepts correct props shape', () => {
    const props = {
      getRemoteUsers: () => mockUsers,
      onVideoCallInitiate: (_userId: string) => {},
      className: 'test-class',
    };
    expect(props.getRemoteUsers).toBeDefined();
    expect(props.onVideoCallInitiate).toBeDefined();
  });

  it('shows correct status indicators', () => {
    const activeUser = mockUsers.get('user-1');
    const idleUser = mockUsers.get('user-3');

    expect(activeUser?.isEditing).toBe(true);
    expect(idleUser?.isEditing).toBe(false);
  });

  it('handles missing cursor positions', () => {
    const userWithNoCursor = mockUsers.get('user-3');
    expect(userWithNoCursor).toBeTruthy();
    expect(userWithNoCursor?.cursor).toBeUndefined();
  });

  it('assigns correct user colors', () => {
    const alice = mockUsers.get('user-1');
    const bob = mockUsers.get('user-2');
    const charlie = mockUsers.get('user-3');

    expect(alice?.cursor?.color).toBe('#ef4444');
    expect(bob?.cursor?.color).toBe('#3b82f6');
    expect(charlie?.cursor).toBeUndefined();
  });

  it('handles empty user map', () => {
    const emptyUsers = new Map<string, RemoteUser>();
    expect(emptyUsers.size).toBe(0);
    expect(Array.from(emptyUsers.values())).toHaveLength(0);
  });
});
