{"version":3,"file":"Modal-DLqdMT83.js","sources":["../../ClientApp/src/js/components/Modal.ts"],"sourcesContent":["const Modal = (id: string) => {\r\n const overlay = document.getElementById(id);\r\n const closeButtons = overlay?.querySelectorAll(\r\n '.js-btn-modal-close',\r\n );\r\n let isModalOpen = false;\r\n\r\n const open = () => {\r\n if (overlay) {\r\n overlay.classList.add('active');\r\n document.body.style.overflow = 'hidden';\r\n isModalOpen = true;\r\n\r\n // Add event listener to overlay only if not already added\r\n if (!overlay.classList.contains('modal-listener-attached')) {\r\n overlay.addEventListener('click', handleOutsideClick);\r\n overlay.classList.add('modal-listener-attached');\r\n }\r\n }\r\n };\r\n\r\n const close = () => {\r\n if (overlay && isModalOpen) {\r\n overlay.classList.remove('active');\r\n document.body.style.overflow = '';\r\n isModalOpen = false;\r\n\r\n // Remove event listener only if present\r\n if (overlay.classList.contains('modal-listener-attached')) {\r\n console.log('Removing click listener from overlay');\r\n overlay.removeEventListener('click', handleOutsideClick);\r\n overlay.classList.remove('modal-listener-attached');\r\n }\r\n }\r\n };\r\n\r\n const handleOutsideClick = (event: MouseEvent) => {\r\n if (isModalOpen) {\r\n // Check if the click target is the overlay itself, not the child elements\r\n if (event.target === overlay) {\r\n console.log('Click outside detected');\r\n close();\r\n }\r\n }\r\n };\r\n\r\n closeButtons?.forEach(closeButton => {\r\n closeButton.addEventListener('click', close);\r\n });\r\n\r\n return {\r\n open,\r\n close,\r\n };\r\n};\r\n\r\nexport default Modal;\r\n"],"names":["Modal","id","overlay","closeButtons","isModalOpen","open","handleOutsideClick","close","event","closeButton"],"mappings":"AAAM,MAAAA,EAASC,GAAe,CACtB,MAAAC,EAAU,SAAS,eAAeD,CAAE,EACpCE,EAAeD,GAAA,YAAAA,EAAS,iBAC5B,uBAEF,IAAIE,EAAc,GAElB,MAAMC,EAAO,IAAM,CACbH,IACMA,EAAA,UAAU,IAAI,QAAQ,EACrB,SAAA,KAAK,MAAM,SAAW,SACjBE,EAAA,GAGTF,EAAQ,UAAU,SAAS,yBAAyB,IAC/CA,EAAA,iBAAiB,QAASI,CAAkB,EAC5CJ,EAAA,UAAU,IAAI,yBAAyB,GAEnD,EAGIK,EAAQ,IAAM,CACdL,GAAWE,IACLF,EAAA,UAAU,OAAO,QAAQ,EACxB,SAAA,KAAK,MAAM,SAAW,GACjBE,EAAA,GAGVF,EAAQ,UAAU,SAAS,yBAAyB,IACtD,QAAQ,IAAI,sCAAsC,EAC1CA,EAAA,oBAAoB,QAASI,CAAkB,EAC/CJ,EAAA,UAAU,OAAO,yBAAyB,GAEtD,EAGII,EAAsBE,GAAsB,CAC5CJ,GAEEI,EAAM,SAAWN,IACnB,QAAQ,IAAI,wBAAwB,EAC9BK,IAEV,EAGF,OAAAJ,GAAA,MAAAA,EAAc,QAAuBM,GAAA,CACvBA,EAAA,iBAAiB,QAASF,CAAK,CAAA,GAGtC,CACL,KAAAF,EACA,MAAAE,CAAA,CAEJ"}