import{r as e,c as t,h as i,H as s,g as a}from"./p-ClISz4NF.js";import{g as o,a as d,c}from"./p-CoD1xawt.js";import{c as l}from"./p-CgDnDrq5.js";import{a as h}from"./p-CDIRBJsi.js";import{c as n}from"./p-vN03FcXN.js";import{t as b}from"./p-Cjg0wpDG.js";import"./p-CQvUntGY.js";import"./p-DNztiAH0.js";const r={root:"gov-dialog",dialog:"gov-dialog__dialog",inner:"gov-dialog__inner",header:"gov-dialog__header",title:"gov-dialog__title",content:"gov-dialog__content",close:"gov-dialog__close",footer:"gov-dialog__footer",bodyFix:"body-fixed"};function f(e){if(!e)return[];return Array.from(e.querySelectorAll('a[href], button:not([disabled]), textarea, input:not([type="hidden"]), select, [tabindex]:not([tabindex="-1"])'))}const g=class{constructor(i){e(this,i);this.govClose=t(this,"gov-close");this.hydrated=false;this.open=false;this.blockClose=false;this.blockBackdropClose=false;this.role="dialog";this.labelTag="h2";this.accessibleCloseLabel="Zavřít okno";this.h=o(this.host);this.labelId=n("GovDialogLabel");this.contentId=n("GovDialogContent")}watchOpen(e){var t;this.open=e;this.setFocus().finally();if(!e){(t=this.lastActiveElementRef)===null||t===void 0?void 0:t.focus()}else{this.focusTrap()}}showDialog(){this.open=true;document.body.classList.add(r.bodyFix)}hideDialog(){this.open=false;document.body.classList.remove(r.bodyFix)}async componentDidRender(){if(l()){b((()=>this.validateAccessibility()))}if(this.open){this.showDialog()}else{this.hideDialog()}}focusTrap(){var e;if(open&&this.dialogRef){this.lastActiveElementRef=document.activeElement;const e=f(this.dialogRef);if(e.length){e[0].focus()}const t=e=>{if(e.key==="Tab"&&this.dialogRef){const t=f(this.dialogRef);const i=t[0];const s=t[t.length-1];if(!e.shiftKey&&document.activeElement===s){e.preventDefault();i.focus()}if(e.shiftKey&&document.activeElement===i){e.preventDefault();s.focus()}}if(e.key==="Escape"){if(this.blockClose===false){this.hideDialog();this.govClose.emit()}}};document.addEventListener("keydown",t)}else{(e=this.lastActiveElementRef)===null||e===void 0?void 0:e.focus()}}connectedCallback(){this.hydrated=true}disconnectedCallback(){document.body.classList.remove(r.bodyFix)}render(){return i(s,{key:"ba9070ed36ce25806a12a88f55d9a36609e17bbb",class:this.h.classes(r.root),open:this.open,hydrated:this.hydrated},i("dialog",{key:"79188b6182895a7a7db32e629316a46420d2981c",ref:e=>this.dialogRef=e,class:r.dialog,hidden:!this.open,tabindex:c(this.open),open:this.open,"aria-modal":"true","aria-hidden":d(!this.open),"aria-labelledby":this.accessibleLabelledBy||this.labelId,"aria-describedby":this.accessibleDescribedBy||this.contentId,role:this.role},i("div",{key:"a50c41b27b3060292df9b6d2eb657c1e27a384e7",class:r.inner},i("div",{key:"487b4639e842aa7257e2ce24a553e8ae67be02be",class:r.header},this.h.hasSlot("icon")&&i("span",{key:"75dfd64444588ce6a37607a60eb1c4df7888d3e8"},i("slot",{key:"80be9198860ffce669b218b6f0f0143f7da83add",name:"icon"})),this.h.hasSlot("title")&&i("span",{key:"723a628454f0989db5da7a1ae12aef803896b9de",class:r.title,id:this.labelId},i("slot",{key:"0aee99ddbdbb0a068b07259d6b2793ddf3dfa629",name:"title"})),i("gov-button",{key:"6f245f5f2a3a95ff239cd55640c5aac980374cfc",ref:e=>this.closeCtaRef=e,disabled:this.blockClose,class:r.close,color:"primary","aria-label":this.accessibleCloseLabel,"aria-labelledby":this.accessibleCloseLabelledBy,type:"base",size:"m","on-gov-click":this.onCloseHandler.bind(this)},i("gov-icon",{key:"f767a25f40e13c322d6871275d996493bbe8730b",slot:"icon-start",name:"x-lg",type:"components"}))),i("div",{key:"4c975dfa826bada579b1ee6edbcece08bf6b7346",class:r.content,id:this.contentId},i("slot",{key:"cdc3d7b173b47237cecf113e344d2ebd05d6daeb"})),this.h.hasSlot("footer")&&i("div",{key:"37e471ea3bb0952c0ccfc290b02af6d69690ae4e",class:r.footer},i("slot",{key:"69f6160c0429d82051a6b99d210f132c7ec3ff56",name:"footer"})))),this.open?i("gov-backdrop",{disabled:this.blockBackdropClose,"aria-label":this.accessibleCloseLabel,"aria-labelled-by":this.accessibleCloseLabelledBy,"on-gov-click":this.onCloseHandler.bind(this)}):null)}onCloseHandler(e){e.stopPropagation();e.preventDefault();if(this.blockClose===false){this.hideDialog();this.govClose.emit(e)}}async setFocus(){if(this.open&&this.closeCtaRef){this.closeCtaRef.setFocus().catch()}}async validateAccessibility(){h(this.accessibleLabelledBy,"accessible-labelled-by",r.root);h(this.accessibleDescribedBy,"accessible-described-by",r.root)}get host(){return a(this)}static get watchers(){return{open:["watchOpen"]}}};export{g as gov_dialog};
//# sourceMappingURL=p-264cbd4e.entry.js.map