"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
(() => {
const sunrise = exports.sunrise;
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');
// eslint-disable-next-line complexity
function renderContracts(rawResponseJSON) {
const responseJSON = rawResponseJSON;
if (responseJSON.contracts.length === 0) {
searchResultsContainerElement.innerHTML = `
There are no contracts that meet the search criteria.
`;
return;
}
const resultsTbodyElement = document.createElement('tbody');
const nowDateString = cityssm.dateToString(new Date());
for (const contract of responseJSON.contracts) {
let contractTimeHTML = '';
if (contract.contractStartDateString <= nowDateString &&
(contract.contractEndDateString === '' ||
contract.contractEndDateString >= nowDateString)) {
contractTimeHTML = `
`;
}
else if (contract.contractStartDateString > nowDateString) {
contractTimeHTML = `
`;
}
else {
contractTimeHTML = `
`;
}
let contactsHTML = '';
for (const interment of contract.contractInterments ?? []) {
contactsHTML += `
${cityssm.escapeHTML(interment.deceasedName ?? '')}
`;
}
if (contract.purchaserName !== '') {
contactsHTML += `
${cityssm.escapeHTML(contract.purchaserName)}
`;
}
if (contract.funeralHomeName !== null &&
contract.funeralHomeName !== '') {
contactsHTML += `
${cityssm.escapeHTML(contract.funeralHomeName)}
`;
}
const feeTotal = (contract.contractFees?.reduce((soFar, currentFee) => soFar +
((currentFee.feeAmount ?? 0) + (currentFee.taxAmount ?? 0)) *
(currentFee.quantity ?? 0), 0) ?? 0).toFixed(2);
const transactionTotal = (contract.contractTransactions?.reduce((soFar, currentTransaction) => soFar + currentTransaction.transactionAmount, 0) ?? 0).toFixed(2);
let feeIconHTML = '';
if (feeTotal !== '0.00' || transactionTotal !== '0.00') {
feeIconHTML = `
`;
}
// eslint-disable-next-line no-unsanitized/method
resultsTbodyElement.insertAdjacentHTML('beforeend', `
|
${contractTimeHTML}
|
${cityssm.escapeHTML(contract.contractType)}
#${contract.contractId}
|
${(contract.burialSiteId ?? -1) === -1
? '(No Burial Site)'
: `
${cityssm.escapeHTML(contract.burialSiteName ?? '')}
`}
${cityssm.escapeHTML(contract.cemeteryName ?? '')}
|
${contract.contractStartDateString}
|
${contract.contractEndDate
? contract.contractEndDateString
: '(No End Date)'}
|
${contactsHTML === ''
? ''
: ``}
|
${feeIconHTML}
|
${contract.printEJS
? `
`
: ''} |
`);
}
searchResultsContainerElement.innerHTML = `