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

\n There are no additional fields for this ${o.escapedAliases.lot} type.\n

\n
`);e.innerHTML="";let i="";for(const t of a.lotTypeFields){i+=`,${t.lotTypeFieldId.toString()}`;const o=`lotFieldValue_${t.lotTypeFieldId.toString()}`,a=`lot--${o}`,r=document.createElement("div");if(r.className="field",r.innerHTML=`\n
`,r.querySelector("label").textContent=t.lotTypeField,""===t.lotTypeFieldValues){const e=document.createElement("input");e.className="input",e.id=a,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=null!==(l=t.pattern)&&void 0!==l?l:""),null===(s=r.querySelector(".control"))||void 0===s||s.append(e)}else{r.querySelector(".control").innerHTML=`
\n \n
`;const e=r.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(r)}e.insertAdjacentHTML("beforeend",``)}):e.innerHTML=`
\n

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

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

There are no comments to display.

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