import{o as p}from"./animation-7e2d11a2.js";import{g as m}from"./request-a636442b.js";const f={bindListeners(){document.addEventListener("click",o=>{const e=o.target.closest("[data-dialog-open-remote]");if(!e)return;o.preventDefault();const i=e.getAttribute("data-dialog-open-remote"),r=e.getAttribute("href")||e.getAttribute("data-remote-url"),n=e.getAttribute("data-remote-route-url"),d=!e.hasAttribute("data-remote-disable-reload"),s=e.hasAttribute("data-dialog-prevent-light-dismiss"),a=e.hasAttribute("data-dialog-non-modal-mode");if(!r||!i)return;if(n&&(o.ctrlKey||o.metaKey)){window.open(n,"_blank");return}const l={url:r,dialogId:i,shouldReload:d,preventLightDismiss:s,routeUrl:n,nonModalMode:a};this.openRemote(l)}),window.addEventListener("popstate",o=>{var e,i;if(((e=o.state)==null?void 0:e.action)==="OPEN_DIALOG")this.openRemote({...o.state.options,routeUrl:null});else if(((i=o.state)==null?void 0:i.action)==="CLOSE_DIALOG"){const r=document.querySelector(`drb-dialog#${o.state.dialogId}`);r==null||r.close()}})},openRemote(o){const{url:e,dialogId:i,shouldReload:r=!0,preventLightDismiss:n=!1,routeUrl:d=null,nonModalMode:s=!1,remoteLoadingSlotHtml:a=null,remoteInitialHeight:l=null,shouldResetIsFetching:h=!0}=o;let t=document.querySelector(`drb-dialog#${i}`);return t&&r&&(t.remove(),t=null),t||(t=document.createElement("drb-dialog"),t.id=i,t.innerHTML=`
${a?`
${a}
`:""} `,document.body.appendChild(t)),t.remoteUrl=e,t.remoteShouldReload=r,t.preventLightDismiss=n,t.nonModalMode=s,t.shouldResetIsFetching=h,l&&t.style.setProperty("--dialog-remote-initial-height",l),d&&(window.history.replaceState({action:"CLOSE_DIALOG",ignoreLegacyRouterCSRF:m(),dialogId:i,title:document.title},""),window.history.pushState({action:"OPEN_DIALOG",options:o,ignoreLegacyRouterCSRF:m(),title:document.title},"",d)),t.addEventListener("drb-dialog-closed",()=>{var u,c,g;((u=window.history.state)==null?void 0:u.action)==="OPEN_DIALOG"&&((g=(c=window.history.state)==null?void 0:c.options)==null?void 0:g.dialogId)===i&&window.history.back()},{once:!0}),p(()=>{t.open()}),t}};export{f as D}; //# sourceMappingURL=drb-dialog-helpers-eb8a8feb.js.map