"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),(()=>{var e;const t=exports.los,o=document.querySelector("#lot--lotId").value,n=""===o;let l=n;function s(){var e;t.setUnsavedChanges(),null===(e=document.querySelector("button[type='submit'][form='form--lot']"))||void 0===e||e.classList.remove("is-light")}function a(){var e;t.clearUnsavedChanges(),null===(e=document.querySelector("button[type='submit'][form='form--lot']"))||void 0===e||e.classList.add("is-light")}const i=document.querySelector("#form--lot");i.addEventListener("submit",function(e){e.preventDefault(),cityssm.postJSON(t.urlPrefix+"/lots/"+(n?"doCreateLot":"doUpdateLot"),i,e=>{var o;const s=e;s.success?(a(),n||l?window.location.href=t.getLotURL(s.lotId,!0,!0):bulmaJS.alert({message:t.escapedAliases.Lot+" Updated Successfully",contextualColorName:"success"})):bulmaJS.alert({title:"Error Updating "+t.escapedAliases.Lot,message:null!==(o=s.errorMessage)&&void 0!==o?o:"",contextualColorName:"danger"})})});const r=i.querySelectorAll("input, select");for(const e of r)e.addEventListener("change",s);t.initializeUnlockFieldButtons(i),null===(e=document.querySelector("#button--deleteLot"))||void 0===e||e.addEventListener("click",e=>{e.preventDefault(),bulmaJS.confirm({title:"Delete "+t.escapedAliases.Lot,message:`Are you sure you want to delete this ${t.escapedAliases.lot}?`,contextualColorName:"warning",okButton:{text:`Yes, Delete ${t.escapedAliases.Lot}`,callbackFunction:function(){cityssm.postJSON(t.urlPrefix+"/lots/doDeleteLot",{lotId:o},e=>{var o;const n=e;n.success?(a(),window.location.href=t.getLotURL()):bulmaJS.alert({title:`Error Deleting ${t.escapedAliases.Lot}`,message:null!==(o=n.errorMessage)&&void 0!==o?o:"",contextualColorName:"danger"})})}}})});const d=document.querySelector("#lot--lotTypeId");if(n){const e=document.querySelector("#container--lotFields");d.addEventListener("change",()=>{""!==d.value?cityssm.postJSON(t.urlPrefix+"/lots/doGetLotTypeFields",{lotTypeId:d.value},o=>{var n;const l=o;if(0===l.lotTypeFields.length)return void(e.innerHTML=`
\n

There are no additional fields for this ${t.escapedAliases.lot} type.

\n
`);e.innerHTML="";let s="";for(const t of l.lotTypeFields){s+=","+t.lotTypeFieldId.toString();const o="lotFieldValue_"+t.lotTypeFieldId.toString(),l="lot--"+o,a=document.createElement("div");if(a.className="field",a.innerHTML=`\n
`,a.querySelector("label").textContent=t.lotTypeField,""===t.lotTypeFieldValues){const e=document.createElement("input");e.className="input",e.id=l,e.name=o,e.type="text",e.required=t.isRequired,e.minLength=t.minimumLength,e.maxLength=t.maximumLength,""!==(null!==(n=t.pattern)&&void 0!==n?n:"")&&(e.pattern=t.pattern),a.querySelector(".control").append(e)}else{a.querySelector(".control").innerHTML=`
\n \n
`;const e=a.querySelector("select");e.required=t.isRequired;const n=t.lotTypeFieldValues.split("\n");for(const t of n){const o=document.createElement("option");o.value=t,o.textContent=t,e.append(o)}}e.append(a)}e.insertAdjacentHTML("beforeend",``)}):e.innerHTML=`
\n

Select the ${t.escapedAliases.lot} type to load the available fields.

\n
`})}else{const e=d.value;d.addEventListener("change",()=>{d.value!==e&&bulmaJS.confirm({title:"Confirm Change",message:`Are you sure you want to change the ${t.escapedAliases.lot} type?\n\n This change affects the additional fields associated with this record.`,contextualColorName:"warning",okButton:{text:"Yes, Keep the Change",callbackFunction:()=>{l=!0}},cancelButton:{text:"Revert the Change",callbackFunction:()=>{d.value=e}}})})}let m=exports.lotComments;function c(e){const n=Number.parseInt(e.currentTarget.closest("tr").dataset.lotCommentId,10),l=m.find(e=>e.lotCommentId===n);let s,a;function i(e){e.preventDefault(),cityssm.postJSON(t.urlPrefix+"/lots/doUpdateLotComment",s,e=>{var t;const o=e;o.success?(m=o.lotComments,a(),p()):bulmaJS.alert({title:"Error Updating Comment",message:null!==(t=o.errorMessage)&&void 0!==t?t:"",contextualColorName:"danger"})})}cityssm.openHtmlModal("lot-editComment",{onshow:e=>{t.populateAliases(e),e.querySelector("#lotCommentEdit--lotId").value=o,e.querySelector("#lotCommentEdit--lotCommentId").value=n.toString(),e.querySelector("#lotCommentEdit--lotComment").value=l.lotComment;const s=e.querySelector("#lotCommentEdit--lotCommentDateString");s.value=l.lotCommentDateString;const a=cityssm.dateToString(new Date);s.max=l.lotCommentDateString<=a?a:l.lotCommentDateString,e.querySelector("#lotCommentEdit--lotCommentTimeString").value=l.lotCommentTimeString},onshown:(e,o)=>{bulmaJS.toggleHtmlClipped(),t.initializeDatePickers(e),e.querySelector("#lotCommentEdit--lotComment").focus(),(s=e.querySelector("form")).addEventListener("submit",i),a=o},onremoved:()=>{bulmaJS.toggleHtmlClipped()}})}function u(e){const n=Number.parseInt(e.currentTarget.closest("tr").dataset.lotCommentId,10);bulmaJS.confirm({title:"Remove Comment?",message:"Are you sure you want to remove this comment?",okButton:{text:"Yes, Remove Comment",callbackFunction:function(){cityssm.postJSON(t.urlPrefix+"/lots/doDeleteLotComment",{lotId:o,lotCommentId:n},e=>{var t;const o=e;o.success?(m=o.lotComments,p()):bulmaJS.alert({title:"Error Removing Comment",message:null!==(t=o.errorMessage)&&void 0!==t?t:"",contextualColorName:"danger"})})}},contextualColorName:"warning"})}function p(){var e,t;const o=document.querySelector("#container--lotComments");if(0===m.length)return void(o.innerHTML='
\n

There are no comments to display.

\n
');const n=document.createElement("table");n.className="table is-fullwidth is-striped is-hoverable",n.innerHTML='\n Commentor\n Comment Date\n Comment\n Options\n \n ';for(const o of m){const l=document.createElement("tr");l.dataset.lotCommentId=o.lotCommentId.toString(),l.innerHTML=""+cityssm.escapeHTML(null!==(e=o.recordCreate_userName)&&void 0!==e?e:"")+""+o.lotCommentDateString+(0===o.lotCommentTime?"":" "+o.lotCommentTimePeriodString)+""+cityssm.escapeHTML(null!==(t=o.lotComment)&&void 0!==t?t:"")+'
',l.querySelector(".button--edit").addEventListener("click",c),l.querySelector(".button--delete").addEventListener("click",u),n.querySelector("tbody").append(l)}o.innerHTML="",o.append(n)}delete exports.lotComments,n||(document.querySelector("#lotComments--add").addEventListener("click",function(){let e;function n(o){o.preventDefault(),cityssm.postJSON(t.urlPrefix+"/lots/doAddLotComment",o.currentTarget,t=>{const o=t;o.success&&(m=o.lotComments,p(),e())})}cityssm.openHtmlModal("lot-addComment",{onshow(e){t.populateAliases(e),e.querySelector("#lotCommentAdd--lotId").value=o,e.querySelector("form").addEventListener("submit",n)},onshown(t,o){bulmaJS.toggleHtmlClipped(),e=o,t.querySelector("#lotCommentAdd--lotComment").focus()},onremoved(){bulmaJS.toggleHtmlClipped(),document.querySelector("#lotComments--add").focus()}})}),p())})();