/**
 * Neon Nights - HTML5 Slot Game
 * Cascading reels with multipliers and bonus features
 */

import { HTML5GameConfig, createHTML5Game } from '../html5GameTemplate.ts';

export const neonNightsConfig: HTML5GameConfig = {
  id: 'neon-nights',
  name: 'Neon Nights',
  description: 'Futuristic game with cascading reels and multipliers',
  thumbnail: '🌃',
  rtp: 96.2,
  volatility: 'high',
  minBet: 0.1,
  maxBet: 100,
  reels: 5,
  rows: 4,
  paylines: 40,
  symbols: [
    {
      id: 'neon-circle',
      name: 'Neon Circle',
      emoji: '🔵',
      payouts: { 5: 500, 4: 100, 3: 20 },
    },
    {
      id: 'neon-square',
      name: 'Neon Square',
      emoji: '🟦',
      payouts: { 5: 400, 4: 80, 3: 15 },
    },
    {
      id: 'neon-triangle',
      name: 'Neon Triangle',
      emoji: '🔺',
      payouts: { 5: 300, 4: 60, 3: 12 },
    },
    {
      id: 'neon-star',
      name: 'Neon Star',
      emoji: '⭐',
      payouts: { 5: 250, 4: 50, 3: 10 },
    },
    {
      id: 'neon-heart',
      name: 'Neon Heart',
      emoji: '💜',
      payouts: { 5: 200, 4: 40, 3: 8 },
    },
    {
      id: 'neon-lightning',
      name: 'Neon Lightning',
      emoji: '⚡',
      payouts: { 5: 1000, 4: 200, 3: 50 },
      isWild: true,
    },
    {
      id: 'neon-gem',
      name: 'Neon Gem',
      emoji: '💎',
      payouts: { 5: 2000, 4: 400, 3: 100 },
      isScatter: true,
    },
  ],
  features: [
    {
      name: 'Cascading Reels',
      description: 'Winning symbols disappear and new ones fall down',
      triggerCondition: 'After any win',
    },
    {
      name: 'Multiplier',
      description: 'Each cascade increases multiplier by 1x',
      triggerCondition: 'During cascades',
    },
    {
      name: 'Wild Symbol',
      description: 'Lightning bolt substitutes for any symbol',
      triggerCondition: 'Random',
    },
    {
      name: 'Free Spins',
      description: 'Get 3+ Neon Gems to trigger free spins',
      triggerCondition: 'Scatter symbol',
    },
  ],
  bonusRounds: [
    {
      id: 'neon-free-spins',
      name: 'Neon Free Spins',
      type: 'free_spins',
      triggerSymbol: 'neon-gem',
      triggerCount: 3,
      reward: 15,
    },
    {
      id: 'neon-respin',
      name: 'Neon Respin',
      type: 'respin',
      triggerSymbol: 'neon-lightning',
      triggerCount: 2,
      reward: 5,
    },
  ],
};

/**
 * Create Neon Nights game instance
 */
export function createNeonNightsGame() {
  return createHTML5Game(neonNightsConfig);
}

/**
 * Neon Nights game statistics
 */
export const neonNightsStats = {
  totalSpins: 0,
  totalWagered: 0,
  totalWon: 0,
  playerCount: 0,
  averageWin: 0,
  biggestWin: 0,
  cascadeCount: 0,
  freeSpinCount: 0,
};

/**
 * Neon Nights game features
 */
export const neonNightsFeatures = {
  cascadingReels: {
    enabled: true,
    maxCascades: 10,
    multiplierIncrease: 1,
  },
  wildSymbol: {
    enabled: true,
    symbol: 'neon-lightning',
    expandable: true,
  },
  freeSpins: {
    enabled: true,
    triggerCount: 3,
    initialSpins: 15,
    additionalSpinsPerTrigger: 5,
  },
  respins: {
    enabled: true,
    triggerCount: 2,
    respinCount: 5,
  },
  progressiveJackpot: {
    enabled: false,
    startAmount: 1000,
    contributionPercentage: 0.1,
  },
};

/**
 * Calculate Neon Nights specific features
 */
export function calculateNeonNightsWin(
  baseWin: number,
  cascadeCount: number,
  isFreeSpin: boolean
): {
  baseWin: number;
  cascadeMultiplier: number;
  freeSpinMultiplier: number;
  totalWin: number;
} {
  const cascadeMultiplier = 1 + cascadeCount * neonNightsFeatures.cascadingReels.multiplierIncrease;
  const freeSpinMultiplier = isFreeSpin ? 1.5 : 1;
  const totalWin = baseWin * cascadeMultiplier * freeSpinMultiplier;

  return {
    baseWin,
    cascadeMultiplier,
    freeSpinMultiplier,
    totalWin,
  };
}
