import { History } from 'lucide-react' import { useCallback, useRef } from 'react' import { useTranslation } from 'react-i18next' import historyBg from '@/assets/system/history-bg.png' import { SmartBackground } from '@/components/smart-background.tsx' import { SmartImage } from '@/components/smart-image' import { DataLoadingIndicator } from '@/components/ui/data-loading-indicator' import { FLOWER_IMAGE_BY_ID } from '@/features/game/shared' import { useGameHistoryVm } from '@/hooks/use-game-history-vm.ts' function HistoryRewardNumber({ className, number, }: { className?: string number: number }) { const image = FLOWER_IMAGE_BY_ID[number] const label = String(number).padStart(2, '0') if (!image?.rewardUrl) { return ( {label} ) } return ( ) } function HistoryEmptyState({ label }: { label: string }) { return (
{label}
) } export function DesktopGameHistory() { const { t } = useTranslation() const { emptyText, endText, fetchNextPage, hasNextPage, isEmpty, isFetchingNextPage, isInitialLoading, items, loadingText, } = useGameHistoryVm() const parentRef = useRef(null) const handleScroll = useCallback(() => { const element = parentRef.current if (!element || !hasNextPage || isFetchingNextPage) { return } const distanceToBottom = element.scrollHeight - element.scrollTop - element.clientHeight if (distanceToBottom <= 120) { void fetchNextPage() } }, [fetchNextPage, hasNextPage, isFetchingNextPage]) return (
{t('gameDesktop.history.title')}
{isInitialLoading ? ( ) : isEmpty ? ( ) : ( <> {items.map((item) => { const isWin = item.resultState === 'win' const statusLabel = item.resultState === 'pending' ? t('gameDesktop.history.pending') : isWin ? t('gameDesktop.history.win') : t('gameDesktop.history.lost') const statusColor = item.resultState === 'pending' ? '#D5FBFF' : isWin ? '#FFE375' : '#8DFF98' const statusTextShadow = item.resultState === 'pending' ? '0 0 calc(var(--design-unit)*10) rgba(213,251,255,0.85), 0 0 calc(var(--design-unit)*22) rgba(213,251,255,0.32)' : isWin ? '0 0 calc(var(--design-unit)*10) #FFE375, 0 0 calc(var(--design-unit)*22) rgba(255,227,117,0.48)' : '0 0 calc(var(--design-unit)*10) #8DFF98, 0 0 calc(var(--design-unit)*22) rgba(141,255,152,0.48)' const statusBorderColor = item.resultState === 'pending' ? 'rgba(143,241,255,0.34)' : isWin ? 'rgba(255,227,117,0.5)' : 'rgba(141,255,152,0.36)' const statusBg = item.resultState === 'pending' ? 'linear-gradient(180deg,rgba(28,106,126,0.38),rgba(5,25,36,0.9))' : isWin ? 'linear-gradient(180deg,rgba(127,92,14,0.5),rgba(29,22,8,0.92))' : 'linear-gradient(180deg,rgba(31,111,54,0.38),rgba(6,28,20,0.92))' return (
) })}
{isFetchingNextPage ? ( ) : hasNextPage ? ( '' ) : ( endText )}
)}
) }