/**
 * Mock data for UiDataTable stories and testing.
 * Keep test data separate from component logic for cleaner architecture.
 */

export interface Payment {
  /** Unique payment identifier */
  id: string;
  /** Payment amount in cents */
  amount: number;
  /** Current payment status */
  status: 'pending' | 'processing' | 'success' | 'failed';
  /** Customer email address */
  email: string;
}

function pickCyclic<T>(items: T[], index: number): T {
  const item = items[index % items.length];
  if (item === undefined) {
    throw new Error('Expected mock data source to contain at least one item');
  }

  return item;
}

// Utility to generate deterministic mock data
function generatePayments(count: number): Payment[] {
  const statuses: Payment['status'][] = [
    'pending',
    'processing',
    'success',
    'failed',
  ];
  const domains = [
    'gmail.com',
    'yahoo.com',
    'hotmail.com',
    'outlook.com',
    'company.com',
  ];
  const firstNames = [
    'John',
    'Jane',
    'Bob',
    'Alice',
    'Charlie',
    'Diana',
    'Edward',
    'Fiona',
    'George',
    'Helen',
    'Ivan',
    'Julia',
    'Kevin',
    'Laura',
    'Michael',
    'Nancy',
    'Oscar',
    'Patricia',
    'Quentin',
    'Rachel',
  ];
  const lastNames = [
    'Smith',
    'Johnson',
    'Williams',
    'Brown',
    'Jones',
    'Garcia',
    'Miller',
    'Davis',
    'Rodriguez',
    'Martinez',
  ];

  return Array.from({ length: count }, (_, i) => {
    const firstName = pickCyclic(firstNames, i);
    const lastName = pickCyclic(lastNames, i);
    const domain = pickCyclic(domains, i);

    return {
      id: `payment-${String(i + 1).padStart(4, '0')}`,
      amount: Math.floor(100 + ((i * 73) % 900)), // Deterministic "random" amounts 100-999
      status: pickCyclic(statuses, i),
      email: `${firstName.toLowerCase()}.${lastName.toLowerCase()}${i > 19 ? i : ''}@${domain}`,
    };
  });
}

/**
 * Small dataset for basic examples (12 items)
 */
export const paymentsSmall: Payment[] = generatePayments(12);

/**
 * Medium dataset for pagination examples (50 items)
 */
export const paymentsMedium: Payment[] = generatePayments(50);

/**
 * Large dataset for stress testing (100 items)
 */
export const paymentsLarge: Payment[] = generatePayments(100);

/**
 * Extra large dataset for performance testing (500 items)
 */
export const paymentsXLarge: Payment[] = generatePayments(500);

/**
 * Default dataset used in most stories
 */
export const payments = paymentsLarge;

/**
 * Dataset options for Storybook controls
 */
export const datasetOptions = {
  'Small (12 items)': paymentsSmall,
  'Medium (50 items)': paymentsMedium,
  'Large (100 items)': paymentsLarge,
  'Extra Large (500 items)': paymentsXLarge,
  Empty: [] as Payment[],
} as const;
