File size: 17,622 Bytes
4c1e4ec dd60672 4c1e4ec dd60672 4c1e4ec dd60672 4c1e4ec dd60672 4c1e4ec |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
import React, { useState, useMemo } from 'react';
import { Target, TrendingUp, Filter, Eye } from 'lucide-react';
import { LotomaniaGame, LotomaniaResult } from '../types';
import { LotomaniaAlgorithm } from '../utils/lotomaniaAlgorithm';
interface GameByGameResultsProps {
allGames: LotomaniaGame[];
algorithm: LotomaniaAlgorithm;
currentResult: LotomaniaResult;
}
interface GameResultDetailed {
game: LotomaniaGame;
numbers: number[];
matchedNumbers: number[];
nonMatchedNumbers: number[];
points: number;
prizeValue: number;
prizeDescription: string;
netProfit: number;
isWinning: boolean;
}
export const GameByGameResults: React.FC<GameByGameResultsProps> = ({
allGames,
algorithm,
currentResult
}) => {
const [filterType, setFilterType] = useState<'all' | 'vertical' | 'horizontal'>('all');
const [filterPoints, setFilterPoints] = useState<'all' | 'winning' | '15+' | '16' | '17+' | '18' | '19+' | '20' | '0'>('all');
const [showGrid, setShowGrid] = useState(true);
const [currentPage, setCurrentPage] = useState(1);
const GAMES_PER_PAGE = 10;
// Analisar todos os jogos
const gameResults = useMemo(() => {
return allGames.map(game => {
const gameNumbers = algorithm.getNumbersFromGame(game);
const matchedNumbers = gameNumbers.filter(num => currentResult.numeros.includes(num));
const nonMatchedNumbers = gameNumbers.filter(num => !currentResult.numeros.includes(num));
let points = matchedNumbers.length;
let prizeValue = 0;
let prizeDescription = 'Sem prêmio';
// Verificar premiação oficial
const premio = currentResult.premiacoes?.find(p => p.acertos === points);
if (premio && points >= 15) {
prizeValue = premio.valorPremio;
prizeDescription = premio.descricao;
} else if (points === 0) {
const premioZero = currentResult.premiacoes?.find(p => p.acertos === 0);
if (premioZero) {
prizeValue = premioZero.valorPremio;
prizeDescription = premioZero.descricao;
}
}
const netProfit = prizeValue - 3.00;
return {
game,
numbers: gameNumbers,
matchedNumbers,
nonMatchedNumbers,
points,
prizeValue,
prizeDescription,
netProfit,
isWinning: prizeValue > 0
};
});
}, [allGames, algorithm, currentResult]);
// Filtrar resultados
const filteredResults = useMemo(() => {
let filtered = gameResults;
if (filterType !== 'all') {
filtered = filtered.filter(r => r.game.type === filterType);
}
if (filterPoints === 'winning') {
filtered = filtered.filter(r => r.isWinning);
} else if (filterPoints === '20') {
filtered = filtered.filter(r => r.points === 20);
} else if (filterPoints === '18') {
filtered = filtered.filter(r => r.points === 18);
} else if (filterPoints === '16') {
filtered = filtered.filter(r => r.points === 16);
} else if (filterPoints === '0') {
filtered = filtered.filter(r => r.points === 0);
} else if (filterPoints !== 'all') {
const minPoints = parseInt(filterPoints.replace('+', ''));
filtered = filtered.filter(r => r.points >= minPoints);
}
return filtered;
}, [gameResults, filterType, filterPoints]);
// Paginação
const totalPages = Math.ceil(filteredResults.length / GAMES_PER_PAGE);
const paginatedResults = filteredResults.slice(
(currentPage - 1) * GAMES_PER_PAGE,
currentPage * GAMES_PER_PAGE
);
// Estatísticas resumidas
const stats = useMemo(() => {
const totalGames = filteredResults.length;
const winningGames = filteredResults.filter(r => r.isWinning).length;
const totalCost = totalGames * 3.00;
const totalPrizes = filteredResults.reduce((sum, r) => sum + r.prizeValue, 0);
// Distribuição por pontos
const pointsDistribution = filteredResults.reduce((acc, r) => {
acc[r.points] = (acc[r.points] || 0) + 1;
return acc;
}, {} as Record<number, number>);
return {
totalGames,
winningGames,
totalCost,
totalPrizes,
netResult: totalPrizes - totalCost,
winRate: (winningGames / totalGames) * 100,
pointsDistribution
};
}, [filteredResults]);
// Renderizar grid de um jogo
const renderGameGrid = (result: GameResultDetailed) => {
if (!showGrid) return null;
return (
<div className="bg-gray-50 p-3 rounded-lg border">
<div className="text-xs font-semibold mb-2 text-gray-700">
🎯 Grid Visual - Jogo #{result.game.id}
</div>
{/* Grid compacto 10x10 */}
<div className="grid grid-cols-10 gap-0.5">
{Array.from({ length: 100 }, (_, i) => {
const number = i;
const isMarked = result.numbers.includes(number);
const isHit = result.matchedNumbers.includes(number);
const wasDrawn = currentResult.numeros.includes(number);
let cellClass = 'w-5 h-5 text-[8px] font-bold flex items-center justify-center border';
if (isMarked && isHit) {
cellClass += ' bg-green-600 text-white'; // Marcado e acertou
} else if (isMarked && !isHit) {
cellClass += ' bg-blue-600 text-white'; // Marcado mas não acertou
} else if (!isMarked && wasDrawn) {
cellClass += ' bg-yellow-400 text-black'; // Não marcado mas saiu
} else {
cellClass += ' bg-white text-gray-600'; // Normal
}
return (
<div
key={number}
className={cellClass}
title={`${number === 0 ? '00' : number} ${isMarked ? '(Marcado)' : ''} ${wasDrawn ? '(Sorteado)' : ''}`}
>
{number === 0 ? '00' : number.toString().padStart(2, '0')}
</div>
);
})}
</div>
{/* Legenda compacta */}
<div className="flex justify-between mt-2 text-[10px] text-gray-600">
<span className="flex items-center gap-1">
<div className="w-2 h-2 bg-green-600 rounded"></div>
Acertou ({result.matchedNumbers.length})
</span>
<span className="flex items-center gap-1">
<div className="w-2 h-2 bg-blue-600 rounded"></div>
Marcado ({result.numbers.length - result.matchedNumbers.length})
</span>
<span className="flex items-center gap-1">
<div className="w-2 h-2 bg-yellow-400 rounded"></div>
Perdeu ({currentResult.numeros.filter(n => !result.numbers.includes(n)).length})
</span>
</div>
</div>
);
};
return (
<div className="space-y-6">
{/* Header */}
<div className="bg-gradient-to-r from-green-600 to-blue-600 text-white p-6 rounded-lg">
<h2 className="text-2xl font-bold flex items-center gap-2">
<Target className="w-6 h-6" />
Resultado Jogo por Jogo
</h2>
<p className="text-green-100 mt-2">
Análise individual de cada um dos {allGames.length} jogos contra o concurso {currentResult.concurso}
</p>
</div>
{/* Estatísticas Resumidas */}
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-5 gap-4">
<div className="bg-blue-50 p-4 rounded-lg border-l-4 border-blue-500">
<span className="text-sm text-blue-600">Jogos Analisados</span>
<p className="text-2xl font-bold text-blue-800">{stats.totalGames}</p>
</div>
<div className="bg-green-50 p-4 rounded-lg border-l-4 border-green-500">
<span className="text-sm text-green-600">Jogos Premiados</span>
<p className="text-2xl font-bold text-green-800">{stats.winningGames}</p>
<p className="text-xs text-green-600">{stats.winRate.toFixed(1)}%</p>
</div>
<div className="bg-yellow-50 p-4 rounded-lg border-l-4 border-yellow-500">
<span className="text-sm text-yellow-600">Total Prêmios</span>
<p className="text-lg font-bold text-yellow-800">
R$ {stats.totalPrizes.toLocaleString('pt-BR', { maximumFractionDigits: 0 })}
</p>
</div>
<div className="bg-red-50 p-4 rounded-lg border-l-4 border-red-500">
<span className="text-sm text-red-600">Custo Total</span>
<p className="text-lg font-bold text-red-800">
R$ {stats.totalCost.toLocaleString('pt-BR', { maximumFractionDigits: 0 })}
</p>
</div>
<div className={`p-4 rounded-lg border-l-4 ${
stats.netResult >= 0 ? 'border-green-500 bg-green-50' : 'border-red-500 bg-red-50'
}`}>
<span className={`text-sm ${stats.netResult >= 0 ? 'text-green-600' : 'text-red-600'}`}>
Resultado
</span>
<p className={`text-lg font-bold ${stats.netResult >= 0 ? 'text-green-800' : 'text-red-800'}`}>
{stats.netResult >= 0 ? '+' : ''}R$ {stats.netResult.toLocaleString('pt-BR', { maximumFractionDigits: 0 })}
</p>
</div>
</div>
{/* Filtros */}
<div className="bg-white p-4 rounded-lg shadow border">
<div className="flex flex-wrap gap-4 items-center">
<Filter className="w-4 h-4 text-gray-500" />
<select
value={filterType}
onChange={(e) => setFilterType(e.target.value as any)}
className="px-3 py-1 border rounded text-sm"
>
<option value="all">Todos os Tipos</option>
<option value="vertical">Verticais ({gameResults.filter(r => r.game.type === 'vertical').length})</option>
<option value="horizontal">Horizontais ({gameResults.filter(r => r.game.type === 'horizontal').length})</option>
</select>
<select
value={filterPoints}
onChange={(e) => setFilterPoints(e.target.value as any)}
className="px-3 py-1 border rounded text-sm"
>
<option value="all">Todas Pontuações</option>
<option value="winning">Apenas Premiados</option>
<option value="15+">15+ Pontos</option>
<option value="16">16 Pontos</option>
<option value="17+">17+ Pontos</option>
<option value="18">18 Pontos</option>
<option value="19+">19+ Pontos</option>
<option value="20">20 Pontos</option>
</select>
<label className="flex items-center gap-2 text-sm">
<input
type="checkbox"
checked={showGrid}
onChange={(e) => setShowGrid(e.target.checked)}
/>
<Eye className="w-4 h-4" />
Grid Visual
</label>
<span className="text-sm text-gray-600">
{filteredResults.length} resultado(s)
</span>
</div>
</div>
{/* Lista de Resultados */}
<div className="space-y-4">
{paginatedResults.map((result) => (
<div
key={result.game.id}
className={`p-4 border rounded-lg ${
result.isWinning ? 'border-green-300 bg-green-50' : 'border-gray-200 bg-white'
}`}
>
<div className="grid grid-cols-1 lg:grid-cols-3 gap-4">
{/* Info do Jogo */}
<div>
<div className="flex items-center gap-3 mb-2">
<div className="bg-blue-600 text-white px-3 py-1 rounded font-bold">
#{result.game.id}
</div>
<div className="text-sm text-gray-600">
<div>{result.game.type === 'vertical' ? '🔹 Vertical' : '🔸 Horizontal'}</div>
<div>Fase {result.game.phase}, Ciclo {result.game.cycle}</div>
</div>
</div>
<div className="space-y-1 text-sm">
<div className="flex justify-between">
<span>Pontuação:</span>
<span className={`font-bold ${result.isWinning ? 'text-green-600' : 'text-gray-600'}`}>
{result.points} pontos
</span>
</div>
<div className="flex justify-between">
<span>Prêmio:</span>
<span className={`font-semibold ${result.isWinning ? 'text-green-600' : 'text-gray-500'}`}>
R$ {result.prizeValue.toLocaleString('pt-BR', { minimumFractionDigits: 2 })}
</span>
</div>
<div className="flex justify-between">
<span>Resultado:</span>
<span className={`font-bold ${result.netProfit >= 0 ? 'text-green-600' : 'text-red-600'}`}>
{result.netProfit >= 0 ? '+' : ''}R$ {result.netProfit.toLocaleString('pt-BR', { minimumFractionDigits: 2 })}
</span>
</div>
{result.isWinning && (
<div className="text-xs text-green-600 mt-1">
🏆 {result.prizeDescription}
</div>
)}
</div>
</div>
{/* Grid Visual */}
<div>
{renderGameGrid(result)}
</div>
{/* Números Detalhados */}
<div className="space-y-3">
<div>
<div className="text-sm font-semibold text-green-600 mb-1">
✅ Acertos ({result.matchedNumbers.length})
</div>
<div className="flex flex-wrap gap-1">
{result.matchedNumbers.map(num => (
<span
key={num}
className="bg-green-600 text-white px-1.5 py-0.5 rounded text-xs font-bold"
>
{num === 0 ? '00' : num.toString().padStart(2, '0')}
</span>
))}
</div>
</div>
<div>
<div className="text-sm font-semibold text-yellow-600 mb-1">
⭐ Perdidos ({currentResult.numeros.filter(n => !result.numbers.includes(n)).length})
</div>
<div className="flex flex-wrap gap-1">
{currentResult.numeros
.filter(n => !result.numbers.includes(n))
.slice(0, 8)
.map(num => (
<span
key={num}
className="bg-yellow-400 text-black px-1.5 py-0.5 rounded text-xs font-bold"
>
{num === 0 ? '00' : num.toString().padStart(2, '0')}
</span>
))}
{currentResult.numeros.filter(n => !result.numbers.includes(n)).length > 8 && (
<span className="text-xs text-gray-500">
+{currentResult.numeros.filter(n => !result.numbers.includes(n)).length - 8}
</span>
)}
</div>
</div>
</div>
</div>
</div>
))}
</div>
{/* Paginação */}
{totalPages > 1 && (
<div className="flex justify-center items-center gap-2">
<button
onClick={() => setCurrentPage(Math.max(1, currentPage - 1))}
disabled={currentPage === 1}
className="px-3 py-1 border rounded disabled:opacity-50"
>
← Anterior
</button>
<span className="px-3 py-1 text-sm">
Página {currentPage} de {totalPages}
</span>
<button
onClick={() => setCurrentPage(Math.min(totalPages, currentPage + 1))}
disabled={currentPage === totalPages}
className="px-3 py-1 border rounded disabled:opacity-50"
>
Próximo →
</button>
</div>
)}
{/* Distribuição de Pontos */}
<div className="bg-white p-4 rounded-lg shadow border">
<h3 className="font-semibold mb-3 flex items-center gap-2">
<TrendingUp className="w-4 h-4" />
Distribuição de Pontuação
</h3>
<div className="grid grid-cols-4 md:grid-cols-8 gap-2">
{Object.entries(stats.pointsDistribution)
.sort(([a], [b]) => parseInt(b) - parseInt(a))
.map(([points, count]) => {
const isWinning = parseInt(points) >= 15 || parseInt(points) === 0;
return (
<div
key={points}
className={`p-2 rounded text-center ${
isWinning ? 'bg-green-100 border border-green-300' : 'bg-gray-100'
}`}
>
<div className={`font-bold ${isWinning ? 'text-green-600' : 'text-gray-600'}`}>
{points}pts
</div>
<div className="text-xs text-gray-600">{count} jogos</div>
</div>
);
})}
</div>
</div>
</div>
);
};
export default GameByGameResults;
|