';
container.innerHTML = html;
// 히스토리에 추가
this.addToHistory(numbers, matchingRound);
},
// 이전 당첨 번호와 비교
findMatchingRound(numbers) {
// 로또 히스토리가 없으면 null 반환
if (!lottoHistory || lottoHistory.length === 0) {
logger.log('로또 히스토리 데이터가 없음');
return null;
}
let bestMatch = null;
let maxMatches = 3; // 최소 3개 이상 일치할 때만 표시
// 모든 히스토리와 비교
for (let round of lottoHistory) {
// numbers 배열의 각 숫자가 round.numbers 배열에 있는지 확인
const matchingNums = numbers.filter(num =>
round.numbers.includes(Number(num)) // 숫자로 변환하여 비교
);
if (matchingNums.length >= maxMatches) {
if (!bestMatch || matchingNums.length > bestMatch.matchCount) {
bestMatch = {
round: round.round,
matchCount: matchingNums.length,
winningNumbers: round.numbers,
matchingNumbers: matchingNums // 일치하는 번호들 저장
};
}
}
}
logger.log('매칭 결과:', bestMatch);
return bestMatch;
},
// 히스토리에 번호 추가
addToHistory(numbers, matchingRound) {
numberHistory.unshift({
numbers,
matchingRound
});
if (numberHistory.length > 10) {
numberHistory.pop();
}
// 히스토리 표시 업데이트
const historyContainer = document.getElementById('numberHistory');
if (historyContainer) {
historyContainer.innerHTML = numberHistory.map((item, index) => `
`).join('');
}
},
// 현재 회차 정보 표시
displayCurrentInfo(info) {
const container = document.getElementById('currentLottoInfo');
if (!container) {
logger.error('현재 회차 정보 컨테이너를 찾을 수 없음');
return;
}
try {
container.innerHTML = `
제 ${info.round}회 (${info.drawDate} 추첨)
${info.winningNumbers.map(num => `
${num}
`).join('')}
+
${info.bonusNumber}
총 판매금액: ${info.totalPrize}
1등 당첨자 수: ${info.firstPrizeCount}명
1등 당첨금액: ${info.firstPrizeAmount}
`;
} catch (error) {
logger.error('현재 회차 정보 표시 실패', error);
container.innerHTML = '
당첨 정보를 표시하는 중 오류가 발생했습니다.
';
}
},
// 로딩 표시
displayLoading(containerId) {
const container = document.getElementById(containerId);
if (container) {
container.innerHTML = `
Loading...
`;
}
},
// 에러 메시지 표시
displayError(containerId, message) {
const container = document.getElementById(containerId);
if (container) {
container.innerHTML = `
${message}
`;
}
}
};
// 회차 정보 모달 표시
async function showRoundInfo(round) {
// 해당 회차 정보 찾기
const roundInfo = lottoHistory.find(info => info.round === round);
if (!roundInfo) {
logger.error('회차 정보를 찾을 수 없음:', round);
alert('회차 정보를 찾을 수 없습니다.');
return;
}
logger.log('회차 정보 표시:', roundInfo);
const modalHtml = `
제 ${roundInfo.round}회 추첨결과
${roundInfo.drawDate} 추첨
${roundInfo.numbers.map(num => `
${num}
`).join('')}
${roundInfo.bonusNumber}
당첨 정보
• 1등: 6개 번호 일치
• 2등: 5개 번호 + 보너스 번호 일치
• 3등: 5개 번호 일치
• 4등: 4개 번호 일치
• 5등: 3개 번호 일치
`;
// 기존 모달 제거
const existingModal = document.getElementById('roundInfoModal');
if (existingModal) {
existingModal.remove();
}
// 새 모달 추가 및 표시
document.body.insertAdjacentHTML('beforeend', modalHtml);
const modal = new bootstrap.Modal(document.getElementById('roundInfoModal'));
modal.show();
}
// 번호 생성 이벤트 핸들러
async function generateNumbers() {
ui.displayLoading('lottoNumbers');
const numbers = await api.generateNumbers();
if (numbers) {
ui.displayNumbers(numbers, 'lottoNumbers');
} else {
ui.displayError('lottoNumbers', '번호 생성에 실패했습니다.');
}
}
// 페이지 초기화
async function initializePage() {
ui.displayLoading('currentLottoInfo');
// 로또 히스토리 로드
lottoHistory = await api.loadLottoHistory();
logger.log('로또 히스토리 로드됨', lottoHistory);
const currentInfo = await api.getCurrentLottoInfo();
if (currentInfo) {
ui.displayCurrentInfo(currentInfo);
// 이전 당첨 번호 저장
previousWinningNumbers.push({
round: currentInfo.round,
winningNumbers: currentInfo.winningNumbers
});
} else {
ui.displayError('currentLottoInfo', '당첨 정보를 불러오는데 실패했습니다.');
}
}
// 페이지 로드 시 초기화
document.addEventListener('DOMContentLoaded', initializePage);