"use strict"; /* eslint-disable @typescript-eslint/no-non-null-assertion, unicorn/prefer-module */ Object.defineProperty(exports, "__esModule", { value: true }); (() => { const los = exports.los; const searchFilterFormElement = document.querySelector('#form--searchFilters'); const searchResultsContainerElement = document.querySelector('#container--searchResults'); const limit = Number.parseInt(document.querySelector('#searchFilter--limit').value, 10); const offsetElement = document.querySelector('#searchFilter--offset'); function renderLotOccupancies(responseJSON) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; if (responseJSON.lotOccupancies.length === 0) { searchResultsContainerElement.innerHTML = `

There are no ${los.escapedAliases.occupancy} records that meet the search criteria.

`; return; } const resultsTbodyElement = document.createElement('tbody'); const nowDateString = cityssm.dateToString(new Date()); for (const lotOccupancy of responseJSON.lotOccupancies) { let occupancyTimeHTML = ''; if (lotOccupancy.occupancyStartDateString <= nowDateString && (lotOccupancy.occupancyEndDateString === '' || lotOccupancy.occupancyEndDateString >= nowDateString)) { occupancyTimeHTML = ` `; } else if (lotOccupancy.occupancyStartDateString > nowDateString) { occupancyTimeHTML = ` `; } else { occupancyTimeHTML = ` `; } let occupantsHTML = ''; for (const occupant of lotOccupancy.lotOccupancyOccupants) { occupantsHTML += '' + (' ') + cityssm.escapeHTML((_c = occupant.occupantName) !== null && _c !== void 0 ? _c : '') + ' ' + cityssm.escapeHTML((_d = occupant.occupantFamilyName) !== null && _d !== void 0 ? _d : '') + '
'; } const feeTotal = ((_f = (_e = lotOccupancy.lotOccupancyFees) === null || _e === void 0 ? void 0 : _e.reduce((soFar, currentFee) => { var _a, _b, _c; return (soFar + (((_a = currentFee.feeAmount) !== null && _a !== void 0 ? _a : 0) + ((_b = currentFee.taxAmount) !== null && _b !== void 0 ? _b : 0)) * ((_c = currentFee.quantity) !== null && _c !== void 0 ? _c : 0)); }, 0)) !== null && _f !== void 0 ? _f : 0).toFixed(2); const transactionTotal = ((_h = (_g = lotOccupancy.lotOccupancyTransactions) === null || _g === void 0 ? void 0 : _g.reduce((soFar, currentTransaction) => { return soFar + currentTransaction.transactionAmount; }, 0)) !== null && _h !== void 0 ? _h : 0).toFixed(2); let feeIconHTML = ''; if (feeTotal !== '0.00' || transactionTotal !== '0.00') { feeIconHTML = ` `; } resultsTbodyElement.insertAdjacentHTML('beforeend', '' + ('' + occupancyTimeHTML + '') + ('' + '' + cityssm.escapeHTML(lotOccupancy.occupancyType) + '' + '') + ('' + (((_j = lotOccupancy.lotId) !== null && _j !== void 0 ? _j : -1) === -1 ? '(No ' + los.escapedAliases.Lot + ')' : '' + cityssm.escapeHTML(lotOccupancy.lotName) + '') + '
' + ('' + cityssm.escapeHTML((_l = lotOccupancy.mapName) !== null && _l !== void 0 ? _l : '') + '') + '') + ('' + lotOccupancy.occupancyStartDateString + '') + ('' + (lotOccupancy.occupancyEndDate ? lotOccupancy.occupancyEndDateString : '(No End Date)') + '') + ('' + occupantsHTML + '') + ('' + feeIconHTML + '') + '' + (lotOccupancy.printEJS ? '' + '' + '' : '') + '' + ''); } searchResultsContainerElement.innerHTML = `
${los.escapedAliases.Occupancy} Type ${los.escapedAliases.Lot} ${los.escapedAliases.OccupancyStartDate} End Date ${los.escapedAliases.Occupants} Fees and Transactions Print
`; searchResultsContainerElement .querySelector('table') .append(resultsTbodyElement); searchResultsContainerElement.insertAdjacentHTML('beforeend', los.getSearchResultsPagerHTML(limit, responseJSON.offset, responseJSON.count)); (_m = searchResultsContainerElement .querySelector("button[data-page='previous']")) === null || _m === void 0 ? void 0 : _m.addEventListener('click', previousAndGetLotOccupancies); (_o = searchResultsContainerElement .querySelector("button[data-page='next']")) === null || _o === void 0 ? void 0 : _o.addEventListener('click', nextAndGetLotOccupancies); } function getLotOccupancies() { searchResultsContainerElement.innerHTML = los.getLoadingParagraphHTML(`Loading ${los.escapedAliases.Occupancies}...`); cityssm.postJSON(los.urlPrefix + '/lotOccupancies/doSearchLotOccupancies', searchFilterFormElement, renderLotOccupancies); } function resetOffsetAndGetLotOccupancies() { offsetElement.value = '0'; getLotOccupancies(); } function previousAndGetLotOccupancies() { offsetElement.value = Math.max(Number.parseInt(offsetElement.value, 10) - limit, 0).toString(); getLotOccupancies(); } function nextAndGetLotOccupancies() { offsetElement.value = (Number.parseInt(offsetElement.value, 10) + limit).toString(); getLotOccupancies(); } const filterElements = searchFilterFormElement.querySelectorAll('input, select'); for (const filterElement of filterElements) { filterElement.addEventListener('change', resetOffsetAndGetLotOccupancies); } searchFilterFormElement.addEventListener('submit', (formEvent) => { formEvent.preventDefault(); }); getLotOccupancies(); })();