H5P.ConfirmationDialog=function(e){function ConfirmationDialog(t){e.call(this);var i=this;H5P.ConfirmationDialog.uniqueId+=1;var n=H5P.ConfirmationDialog.uniqueId;function dialogConfirmed(e){i.hide(),i.trigger("confirmed"),e.preventDefault()}function dialogCanceled(e){i.hide(),i.trigger("canceled"),e.preventDefault()}function flowTo(e,t){e.focus(),t.preventDefault()}(t=t||{}).headerText=t.headerText||H5P.t("confirmDialogHeader"),t.dialogText=t.dialogText||H5P.t("confirmDialogBody"),t.cancelText=t.cancelText||H5P.t("cancelLabel"),t.confirmText=t.confirmText||H5P.t("confirmLabel");var o=!1,a=globalThis.document.createElement("div");a.classList.add("h5p-confirmation-dialog-background","hidden","hiding");var d=globalThis.document.createElement("div");d.classList.add("h5p-confirmation-dialog-popup","hidden"),d.setAttribute("role","dialog"),d.setAttribute("aria-labelledby","h5p-confirmation-dialog-dialog-text-"+n),a.appendChild(d),d.addEventListener("keydown",(function(e){27===e.which&&dialogCanceled(e)}));var r=globalThis.document.createElement("div");r.classList.add("h5p-confirmation-dialog-header"),d.appendChild(r);var l=globalThis.document.createElement("div");l.classList.add("h5p-confirmation-dialog-header-text"),l.innerHTML=t.headerText,r.appendChild(l);var c=globalThis.document.createElement("div");c.classList.add("h5p-confirmation-dialog-body"),d.appendChild(c);var s=globalThis.document.createElement("div");s.classList.add("h5p-confirmation-dialog-text"),s.innerHTML=t.dialogText,s.id="h5p-confirmation-dialog-dialog-text-"+n,c.appendChild(s);var h=globalThis.document.createElement("div");h.classList.add("h5p-confirmation-dialog-buttons"),c.appendChild(h);var u=globalThis.document.createElement("button");u.classList.add("h5p-core-cancel-button"),u.textContent=t.cancelText;var f=globalThis.document.createElement("button");f.classList.add("h5p-core-button"),f.classList.add("h5p-confirmation-dialog-confirm-button"),f.textContent=t.confirmText;var g,m,p=globalThis.document.createElement("button");p.classList.add("h5p-confirmation-dialog-exit"),p.setAttribute("aria-hidden","true"),p.tabIndex=-1,p.title=t.cancelText,u.addEventListener("click",dialogCanceled),u.addEventListener("keydown",(function(e){32===e.which?dialogCanceled(e):9===e.which&&e.shiftKey&&flowTo(f,e)})),h.appendChild(u),f.addEventListener("click",dialogConfirmed),f.addEventListener("keydown",(function(e){32===e.which?dialogConfirmed(e):9!==e.which||e.shiftKey||flowTo(u,e)})),h.appendChild(f),p.addEventListener("click",dialogCanceled),p.addEventListener("keydown",(function(e){32===e.which&&dialogCanceled(e)})),d.appendChild(p);var v,b=[],T=[];this.appendTo=function(e){return g=e,this};var captureFocus=function(e){a.contains(e.target)||(e.preventDefault(),f.focus())},hideSiblings=function(e){var t,i=[],n=e.parentNode.children;for(t=0;t<n.length;t+=1)i[t]=!!n[t].getAttribute("aria-hidden"),n[t]!==e&&n[t].setAttribute("aria-hidden",!0);return i},restoreSiblings=function(e,t){var i,n=e.parentNode.children;for(i=0;i<n.length;i+=1)n[i]===e||t[i]||n[i].removeAttribute("aria-hidden")};this.show=function(e){return v=globalThis.document.activeElement,g.appendChild(a),(m=g.parentNode||g).addEventListener("focus",captureFocus,!0),b=hideSiblings(g),T=hideSiblings(a),a.classList.remove("hidden"),function(e){var t=parseInt(d.style.top,10);e&&(t=e),t+d.offsetHeight>g.offsetHeight&&(t=g.offsetHeight-d.offsetHeight-8),t-32<=0&&(t=40,o=!0),d.style.top=t+"px"}(e),setTimeout((function(){d.classList.remove("hidden"),a.classList.remove("hiding"),setTimeout((function(){if(f.focus(),o&&t.instance){var e=parseInt(d.offsetHeight,10)+32+16;i.setViewPortMinimumHeight(e),t.instance.trigger("resize"),o=!1}}),100)}),0),this},this.hide=function(){return a.classList.add("hiding"),d.classList.add("hidden"),m.removeAttribute("aria-hidden"),m.removeEventListener("focus",captureFocus,!0),v.focus(),restoreSiblings(g,b),restoreSiblings(a,T),setTimeout((function(){a.classList.add("hidden"),g.removeChild(a),i.setViewPortMinimumHeight(null)}),100),this},this.setViewPortMinimumHeight=function(e){(globalThis.document.querySelector(".h5p-container")||globalThis.document.body).style.minHeight="number"==typeof e?e+"px":e}}return ConfirmationDialog.prototype=Object.create(e.prototype),ConfirmationDialog.prototype.constructor=ConfirmationDialog,ConfirmationDialog}(H5P.EventDispatcher),H5P.ConfirmationDialog.uniqueId=-1;