Joomla=window.Joomla||{};((o,m)=>{m.addEventListener("DOMContentLoaded",function(){const e=()=>{const e=m.getElementById("jform_image");const o=m.querySelector(".easystore-profile-image-container");let l="";e.addEventListener("change",e=>{const t=e.target.files[0];const s=d(t);if(s){l=t;const n=o.firstElementChild;const i=URL.createObjectURL(t);const a=n.classList.contains("easystore-svg");if(a){const c=f(i);n.replaceWith(c)}else{n.setAttribute("src",i)}}else{if(!l){e.target.value=null}else{const r=new DataTransfer;r.items.add(l);e.target.files=r.files}}});function d(e){if(!e)return false;return e.type.startsWith("image/")}function f(e="",t=250){const s=m.createElement("img");s.src=e;s.width=t;return s}};const r=m.querySelector(".easystore-same-address");const s=m.getElementsByName("jform[is_billing_same]");const t=()=>{var e;for(var t=0;t<s.length;t++){if(s[t].classList.contains("active")){e=s[t].value;break}}if(e==1){r.classList.add("hidden")}else{r.classList.remove("hidden")}};e();t();m.addEventListener("click",function(t){if(t.target.hasAttribute("easystore-profile-is-same-as-shipping")){const s=t.target.checked;let e=m.querySelector(".billing-content");const n=m.querySelectorAll(".easystore-billing");if(s){e.classList.add("hidden");n.forEach(e=>{e.removeAttribute("required")})}else{e.classList.remove("hidden");n.forEach(e=>{e.setAttribute("required","true")})}}});m.addEventListener("change",function(e){if(e.target.name==="jform[shipping_country]"||e.target.name==="jform[billing_country]"){const s=e.target.name==="jform[shipping_country]"?"jform_shipping_state":"jform_billing_state";const n=e.target.value;const i=o.getOptions("countriesList",false);const a=i.find(e=>e.numeric_code===n);const c=m.getElementById(s).closest("joomla-field-fancy-select");c.choicesInstance.setChoices([{id:"",text:""}],"id","text",false);c.choicesInstance.setChoiceByValue("");var t=m.createEvent("HTMLEvents");t.initEvent("change",true,false);m.getElementById(s).dispatchEvent(t);c.choicesInstance.clearChoices();if(a.states){a.states.forEach(e=>{const t={};t.innerText=e.name;t.id=e.id;c.choicesInstance.setChoices([t],"id","innerText",false)})}}if(e.target.name==="jform[is_billing_same]"){if(e.target.value==1){r.classList.add("hidden")}else{r.classList.remove("hidden")}}})})})(Joomla,document);