var k=Object.defineProperty;var N=(s,a,t)=>a in s?k(s,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[a]=t;var g=(s,a,t)=>N(s,typeof a!="symbol"?a+"":a,t);class u extends HTMLElement{constructor(){super();g(this,"currentImage");this.currentImage=null}static register(t){console.log("Registering image-gallery-bs4!"),"customElements"in window&&customElements.define(t||"image-gallery-bs4",u)}replaceImage(t){if(this.currentImage){const e=this.currentImage.getAttribute(t);if(e==="false")return;const r=this.querySelector("#"+e);r&&this.setModalImage(r)}}setModalImage(t){var b,f;if(this.currentImage=t,!t.parentNode){console.error("No parent node for image: ",t);return}const e=t.parentNode;if(!e.parentNode){console.error("No parent node for thumbnail picture: ",e);return}const r=(b=e.parentNode.getAttribute("data-full"))!=null?b:"",m=e.querySelector("source");if(!m){console.error("No thumbnail source for picture: ",e);return}const n=this.querySelector(`#${this.id} .modal-body`);if(!n){console.error("No modal body for modal: ",this);return}console.log("modalBody: ",n);const h=this.querySelector(`#${this.id} .modal-footer`);if(!h){console.error("No modal footer for modal: ",this);return}const y=[{attr:"data-modal-srcset",prop:"srcset"},{attr:"data-modal-src",prop:"src"},{attr:"type",prop:"type"},{attr:"data-modal-sizes",prop:"sizes"}],p=n.querySelector("source");if(!p){console.error("No modal source for modal body: ",n);return}for(const{attr:d,prop:c}of y){const l=m.getAttribute(d);l&&p.setAttribute(c,l)}const v=[{attr:"alt",prop:"alt"},{attr:"data-prev",prop:"data-prev"},{attr:"data-next",prop:"data-next"},{attr:"data-fullsrc",prop:"src"},{attr:"data-modal-srcset",prop:"srcset"},{attr:"data-modal-sizes",prop:"sizes"},{attr:"data-modal-height",prop:"height"},{attr:"data-modal-width",prop:"width"}],i=n.querySelector("img");if(!i){console.error("No modal image for modal body: ",n);return}((f=i.parentNode)==null?void 0:f.parentNode).setAttribute("href",r);for(const{attr:d,prop:c}of v){const l=t.getAttribute(d);l&&i.setAttribute(c,l)}let o="";i.getAttribute("data-prev")!=="false"?o=o+'<button id="data-prev" type="button" class="btn btn-primary">Prev</button>':o=o+'<button id="data-prev" type="button" class="btn btn-primary disabled">Prev</button>',i.getAttribute("data-next")!=="false"?o=o+'<button id="data-next" type="button" class="btn btn-primary">Next</button>':o=o+'<button id="data-next" type="button" class="btn btn-primary disabled">Next</button>',h.innerHTML=o}handleThumbnailClick(t){t.preventDefault(),t.target;const r=t.currentTarget.querySelector("img");r?this.setModalImage(r):console.error("No img element found in clicked thumbnail")}handleFooterClick(t){const e=t.target;e.matches("#data-prev, #data-next")&&this.replaceImage(e.id)}handleKeydown(t){t.key==="ArrowLeft"&&this.replaceImage("data-prev"),t.key==="ArrowRight"&&this.replaceImage("data-next")}connectedCallback(){this.querySelectorAll(".cast-gallery-container > a").forEach(r=>{r.classList.contains("event-added")||(r.addEventListener("click",this.handleThumbnailClick.bind(this)),r.classList.add("event-added"))});const e=this.querySelector(".modal-footer");e&&e.addEventListener("click",this.handleFooterClick.bind(this)),this.addEventListener("keydown",this.handleKeydown.bind(this))}disconnectedCallback(){this.querySelectorAll(".cast-gallery-container > a").forEach(r=>{r.removeEventListener("click",this.handleThumbnailClick)});const e=this.querySelector(".modal-footer");e&&e.removeEventListener("click",this.handleFooterClick),this.removeEventListener("keydown",this.handleKeydown)}}u.register("image-gallery-bs4");
