var __awaiter=this&&this.__awaiter||function(t,e,i,a){function n(t){return t instanceof i?t:new i((function(e){e(t)}))}return new(i||(i=Promise))((function(i,o){function r(t){try{s(a.next(t))}catch(t){o(t)}}function l(t){try{s(a["throw"](t))}catch(t){o(t)}}function s(t){t.done?i(t.value):n(t.value).then(r,l)}s((a=a.apply(t,e||[])).next())}))};var __generator=this&&this.__generator||function(t,e){var i={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},a,n,o,r;return r={next:l(0),throw:l(1),return:l(2)},typeof Symbol==="function"&&(r[Symbol.iterator]=function(){return this}),r;function l(t){return function(e){return s([t,e])}}function s(r){if(a)throw new TypeError("Generator is already executing.");while(i)try{if(a=1,n&&(o=r[0]&2?n["return"]:r[0]?n["throw"]||((o=n["return"])&&o.call(n),0):n.next)&&!(o=o.call(n,r[1])).done)return o;if(n=0,o)r=[r[0]&2,o.value];switch(r[0]){case 0:case 1:o=r;break;case 4:i.label++;return{value:r[1],done:false};case 5:i.label++;n=r[1];r=[0];continue;case 7:r=i.ops.pop();i.trys.pop();continue;default:if(!(o=i.trys,o=o.length>0&&o[o.length-1])&&(r[0]===6||r[0]===2)){i=0;continue}if(r[0]===3&&(!o||r[1]>o[0]&&r[1]=a){return o}var r=function(t){var o=t.assignedNodes().filter((function(t){return t.nodeType===1}));if(o.length>0){return queryShadowRoot(o[0].parentElement,e,i,a,n+1)}return[]};var l=Array.from(t.children||[]);for(var s=0,c=l;s0){focusElement(t[t.length-1])}else{focusElement(e.closeButtonEl)}};this.updateFooterVisibility=function(){e.hasFooter=!!getSlotted(e.el,[SLOTS.back,SLOTS.primary,SLOTS.secondary])}}t.prototype.componentWillLoad=function(){if(this.active){this.open()}};t.prototype.connectedCallback=function(){var t;(t=this.mutationObserver)===null||t===void 0?void 0:t.observe(this.el,{childList:true,subtree:true});this.updateFooterVisibility();connectConditionalSlotComponent(this)};t.prototype.disconnectedCallback=function(){var t;this.removeOverflowHiddenClass();(t=this.mutationObserver)===null||t===void 0?void 0:t.disconnect();disconnectConditionalSlotComponent(this)};t.prototype.render=function(){var t=this;return h(Host,{"aria-describedby":this.contentId,"aria-labelledby":this.titleId,"aria-modal":"true",role:"dialog"},h("calcite-scrim",{class:CSS.scrim,onClick:this.handleOutsideClose}),this.renderStyle(),h("div",{class:"modal",onTransitionEnd:this.transitionEnd},h("div",{"data-focus-fence":true,onFocus:this.focusLastElement,tabindex:"0"}),h("div",{class:CSS.header},this.renderCloseButton(),h("header",{class:CSS.title},h("slot",{name:CSS.header}))),h("div",{class:{content:true,"content--spaced":!this.noPadding,"content--no-footer":!this.hasFooter},ref:function(e){return t.modalContent=e}},h("slot",{name:SLOTS.content})),this.renderFooter(),h("div",{"data-focus-fence":true,onFocus:this.focusFirstElement,tabindex:"0"})))};t.prototype.renderFooter=function(){return this.hasFooter?h("div",{class:CSS.footer,key:"footer"},h("span",{class:CSS.back},h("slot",{name:SLOTS.back})),h("span",{class:CSS.secondary},h("slot",{name:SLOTS.secondary})),h("span",{class:CSS.primary},h("slot",{name:SLOTS.primary}))):null};t.prototype.renderCloseButton=function(){var t=this;return!this.disableCloseButton?h("button",{"aria-label":this.intlClose,class:CSS.close,key:"button",onClick:this.close,ref:function(e){return t.closeButtonEl=e},title:this.intlClose},h("calcite-icon",{icon:ICONS.close,scale:this.scale==="s"?"s":this.scale==="m"?"m":this.scale==="l"?"l":null})):null};t.prototype.renderStyle=function(){var t=!isNaN(parseInt("".concat(this.width)));return t?h("style",null,"\n .modal {\n max-width: ".concat(this.width,"px !important;\n }\n @media screen and (max-width: ").concat(this.width,"px) {\n .modal {\n height: 100% !important;\n max-height: 100% !important;\n width: 100% !important;\n max-width: 100% !important;\n margin: 0 !important;\n border-radius: 0 !important;\n }\n .content {\n flex: 1 1 auto !important;\n max-height: unset !important;\n }\n }\n ")):null};t.prototype.handleEscape=function(t){if(this.active&&!this.disableEscape&&t.key==="Escape"){this.close()}};t.prototype.focusElement=function(t){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(e){if(t){t.focus()}return[2,this.setFocus()]}))}))};t.prototype.setFocus=function(t){return __awaiter(this,void 0,void 0,(function(){var e;return __generator(this,(function(i){e=this.closeButtonEl;return[2,focusElement(t==="close-button"?e:getFocusableElements(this.el)[0]||e)]}))}))};t.prototype.scrollContent=function(t,e){if(t===void 0){t=0}if(e===void 0){e=0}return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(i){if(this.modalContent){if(this.modalContent.scrollTo){this.modalContent.scrollTo({top:t,left:e,behavior:"smooth"})}else{this.modalContent.scrollTop=t;this.modalContent.scrollLeft=e}}return[2]}))}))};t.prototype.toggleModal=function(t,e){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(i){if(t!==e){if(t){this.open()}else if(!t){this.close()}}return[2]}))}))};t.prototype.open=function(){this.previousActiveElement=document.activeElement;this.el.addEventListener("calciteModalOpen",this.openEnd);this.active=true;var t=getSlotted(this.el,SLOTS.header);var e=getSlotted(this.el,SLOTS.content);this.titleId=ensureId(t);this.contentId=ensureId(e);document.documentElement.classList.add(CSS.overflowHidden)};t.prototype.removeOverflowHiddenClass=function(){document.documentElement.classList.remove(CSS.overflowHidden)};Object.defineProperty(t.prototype,"el",{get:function(){return getElement(this)},enumerable:false,configurable:true});Object.defineProperty(t,"watchers",{get:function(){return{active:["toggleModal"]}},enumerable:false,configurable:true});return t}();Modal.style=modalCss;export{Modal as calcite_modal};