/* eslint-disable unicorn/prefer-module */ import type * as globalTypes from "../types/globalTypes"; import type * as recordTypes from "../types/recordTypes"; import type { cityssmGlobal } from "@cityssm/bulma-webapp-js/src/types"; import type { BulmaJS } from "@cityssm/bulma-js/types"; declare const cityssm: cityssmGlobal; declare const bulmaJS: BulmaJS; (() => { const urlPrefix = document.querySelector("main").dataset.urlPrefix; const containerElement = document.querySelector( "#container--occupancyTypes" ) as HTMLElement; const occupancyTypes: recordTypes.OccupancyType[] = exports.occupancyTypes; delete exports.occupancyTypes; const expandedOccupancyTypes = new Set(); const toggleOccupancyTypeFields = (clickEvent: Event) => { const toggleButtonElement = clickEvent.currentTarget as HTMLButtonElement; const occupancyTypeElement = toggleButtonElement.closest( ".container--occupancyType" ) as HTMLElement; const occupancyTypeId = Number.parseInt( occupancyTypeElement.dataset.occupancyTypeId, 10 ); if (expandedOccupancyTypes.has(occupancyTypeId)) { expandedOccupancyTypes.delete(occupancyTypeId); } else { expandedOccupancyTypes.add(occupancyTypeId); } toggleButtonElement.innerHTML = expandedOccupancyTypes.has( occupancyTypeId ) ? '' : ''; const panelBlockElements = occupancyTypeElement.querySelectorAll(".panel-block"); for (const panelBlockElement of panelBlockElements) { panelBlockElement.classList.toggle("is-hidden"); } }; const renderOccupancyTypes = () => { if (occupancyTypes.length === 0) { containerElement.innerHTML = '
There are no active ' + exports.aliases.occupancy.toLowerCase() + " types.

" + "
"; return; } containerElement.innerHTML = ""; for (const occupancyType of occupancyTypes) { const occupancyTypeContainer = document.createElement("div"); occupancyTypeContainer.className = "panel container--occupancyType"; occupancyTypeContainer.dataset.occupancyTypeId = occupancyType.occupancyTypeId.toString(); occupancyTypeContainer.innerHTML = '
' + '
' + ('
' + '
' + '" + "
" + '
' + '

' + cityssm.escapeHTML(occupancyType.occupancyType) + "

" + "
" + "
") + ('
' + '
' + '" + "
" + '
' + '" + "
" + ('
' + '
' + '
' + '" + "
" + '
' + '" + "
" + "
" + "
") + "
") + "
" + "
"; if (occupancyType.occupancyTypeFields.length === 0) { occupancyTypeContainer.insertAdjacentHTML( "beforeend", '
' + '
' + '

There are no additional fields.

' + "
" + "
" ); } else { for (const occupancyTypeField of occupancyType.occupancyTypeFields) { const panelBlockElement = document.createElement("div"); panelBlockElement.className = "panel-block is-block container--occupancyTypeField"; if ( !expandedOccupancyTypes.has( occupancyType.occupancyTypeId ) ) { panelBlockElement.classList.add("is-hidden"); } panelBlockElement.dataset.occupancyTypeFieldId = occupancyTypeField.occupancyTypeFieldId.toString(); panelBlockElement.innerHTML = '
' + '" + '
' + ('
' + '
' + '
' + '" + "
" + '
' + '" + "
" + "
" + "
") + "
" + "
"; occupancyTypeContainer.append(panelBlockElement); } } occupancyTypeContainer .querySelector(".button--toggleOccupancyTypeFields") .addEventListener("click", toggleOccupancyTypeFields); containerElement.append(occupancyTypeContainer); } }; renderOccupancyTypes(); })();