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

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

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

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

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

There are no comments to display.

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