import subDays from 'date-fns/subDays'; import renderPopup from './renderPopup'; import { generatePaginationItems, getContainerStyles } from './pagination'; import formatDate from './formatDate'; import { formatTribeURL } from './tribalwars'; const HISTORY_PAGINATION_CONTAINER_ID = 'historyPagination'; 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('')}
Date Tribe Points Villages Members OD ODA ODD 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 })
`; renderPopup({ e, title: `History`, id: 'history', html, }); document .querySelectorAll('#' + HISTORY_PAGINATION_CONTAINER_ID + ' a') .forEach((el) => { el.addEventListener('click', onPageChange); }); };