import subDays from 'date-fns/subDays'; import getTranslations from '../i18n/showHistoryPopup'; import showPopup from '../utils/showPopup'; import { generatePaginationItems, getContainerStyles, } from '../utils/pagination'; import { formatDate } from '../utils/date'; import * as twutils from '../utils/tribalwars'; const PAGINATION_CONTAINER_ID = 'historyPagination'; const translations = getTranslations(); const addMathSymbol = v => { return v > 0 ? '+' + v : v; }; export default ( e, history, daily, { currentPage = 1, limit = 0, onPageChange = () => {}, tribe = false } = {} ) => { const paginationItems = generatePaginationItems({ total: history.total, limit, currentPage, }); const html = `
${paginationItems.join('')}
${tribe ? '' : ``} ${tribe ? `` : ''} ${tribe ? '' : ``} ${history.items .map(history => { const subtracted = subDays(new Date(history.createDate), 1) .toISOString() .split('.')[0] + 'Z'; const stats = daily.items.find(stats => { return stats.createDate === subtracted; }); let rowHTML = '' + ``; if (!tribe && history.tribe) { rowHTML += ``; } else if (!tribe) { rowHTML += ''; } rowHTML += ` ${ !tribe ? '' : ` ` } ${ tribe ? '' : ` ` } ` + ''; return rowHTML; }) .join('')}
${translations.date} ${translations.tribe} ${translations.points} ${translations.villages} ${translations.members} ${translations.od} ${translations.oda} ${translations.odd} ${translations.ods}
${formatDate(history.createDate, { year: 'numeric', month: '2-digit', day: '2-digit', })}${history.tribe.tag}- ${history.points.toLocaleString()} (${ history.rank }) ${history.totalVillages.toLocaleString()} ${history.totalMembers} ${history.scoreTotal.toLocaleString()} (${ history.rankTotal }) ${history.scoreAtt.toLocaleString()} (${ history.rankAtt }) ${history.scoreDef.toLocaleString()} (${ history.rankDef }) ${history.scoreSup.toLocaleString()} (${ history.rankSup })
`; showPopup({ e, title: translations.title, id: 'history', html, }); document .querySelectorAll('#' + PAGINATION_CONTAINER_ID + ' a') .forEach(el => { el.addEventListener('click', onPageChange); }); };