import e,{Component as t}from"react";import{UniqueComponentId as i,DomHandler as n,ZIndexUtils as o,classNames as s,ObjectUtils as r}from"primereact/utils";import{CSSTransition as a}from"primereact/csstransition";import{Ripple as l}from"primereact/ripple";import{Portal as d}from"primereact/portal";import c from"primereact/api";function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,n=new Array(t);i=this.props.minX&&a+t=this.props.minY&&l+ic)&&r.left+lp)&&r.top+d0)if(document.activeElement){var d=l.indexOf(document.activeElement);t.shiftKey?-1===d||0===d?l[l.length-1].focus():l[d-1].focus():-1===d||d===l.length-1?l[0].focus():l[d+1].focus()}else l[0].focus()}}}};var t,i={id:this.state.id,hasBlockScroll:this.props.blockScroll};document.primeDialogParams=document.primeDialogParams?[].concat(u(t=document.primeDialogParams)||m(t)||h(t)||g(),[i]):[i],document.addEventListener("keydown",this.documentKeyDownListener)}},{key:"unbindDocumentKeyDownListener",value:function(){var e=this;this.documentKeyDownListener&&(document.removeEventListener("keydown",this.documentKeyDownListener),document.primeDialogParams=document.primeDialogParams&&document.primeDialogParams.filter((function(t){return t.id!==e.state.id})),this.documentKeyDownListener=null)}},{key:"createStyle",value:function(){if(!this.styleElement){this.styleElement=n.createInlineStyle(c.nonce);var e="";for(var t in this.props.breakpoints)e+="\n @media screen and (max-width: ".concat(t,") {\n .p-dialog[").concat(this.attributeSelector,"] {\n width: ").concat(this.props.breakpoints[t]," !important;\n }\n }\n ");this.styleElement.innerHTML=e}}},{key:"componentDidMount",value:function(){var e=this;this.state.id||this.setState({id:i()}),this.props.visible&&this.setState({maskVisible:!0},(function(){o.set("modal",e.mask,c.autoZIndex,e.props.baseZIndex||c.zIndex.modal),e.setState({visible:!0})})),this.props.breakpoints&&this.createStyle()}},{key:"componentDidUpdate",value:function(e){var t=this;this.props.visible&&!this.state.maskVisible&&this.setState({maskVisible:!0},(function(){o.set("modal",t.mask,c.autoZIndex,t.props.baseZIndex||c.zIndex.modal)})),this.props.visible!==this.state.visible&&this.state.maskVisible&&this.setState({visible:this.props.visible}),e.maximized!==this.props.maximized&&this.props.onMaximize&&this.changeScrollOnMaximizable()}},{key:"changeScrollOnMaximizable",value:function(){this.props.blockScroll||n[this.maximized?"addClass":"removeClass"](document.body,"p-overflow-hidden")}},{key:"componentWillUnmount",value:function(){this.disableDocumentSettings(),this.styleElement=n.removeInlineStyle(this.styleElement),o.clear(this.mask)}},{key:"renderCloseIcon",value:function(){var t=this;return this.props.closable?e.createElement("button",{ref:function(e){return t.closeElement=e},type:"button",className:"p-dialog-header-icon p-dialog-header-close p-link","aria-label":this.props.ariaCloseIconLabel,onClick:this.onClose},e.createElement("span",{className:"p-dialog-header-close-icon pi pi-times"}),e.createElement(l,null)):null}},{key:"renderMaximizeIcon",value:function(){var t=s("p-dialog-header-maximize-icon pi",{"pi-window-maximize":!this.maximized,"pi-window-minimize":this.maximized});return this.props.maximizable?e.createElement("button",{type:"button",className:"p-dialog-header-icon p-dialog-header-maximize p-link",onClick:this.toggleMaximize},e.createElement("span",{className:t}),e.createElement(l,null)):null}},{key:"renderHeader",value:function(){var t=this;if(this.props.showHeader){var i=this.renderCloseIcon(),n=this.renderMaximizeIcon(),o=r.getJSXElement(this.props.icons,this.props),s=r.getJSXElement(this.props.header,this.props);return e.createElement("div",{ref:function(e){return t.headerEl=e},className:"p-dialog-header",onMouseDown:this.onDragStart},e.createElement("div",{id:this.state.id+"_header",className:"p-dialog-title"},s),e.createElement("div",{className:"p-dialog-header-icons"},o,n,i))}return null}},{key:"renderContent",value:function(){var t=this,i=s("p-dialog-content",this.props.contentClassName);return e.createElement("div",{id:this.state.id+"_content",ref:function(e){return t.contentEl=e},className:i,style:this.props.contentStyle},this.props.children)}},{key:"renderFooter",value:function(){var t=this,i=r.getJSXElement(this.props.footer,this.props);return i&&e.createElement("div",{ref:function(e){return t.footerElement=e},className:"p-dialog-footer"},i)}},{key:"renderResizer",value:function(){return this.props.resizable?e.createElement("div",{className:"p-resizable-handle",style:{zIndex:90},onMouseDown:this.onResizeStart}):null}},{key:"renderElement",value:function(){var t=this,i=s("p-dialog p-component",this.props.className,{"p-dialog-rtl":this.props.rtl,"p-dialog-maximized":this.maximized}),n=s("p-dialog-mask",{"p-component-overlay p-component-overlay-enter":this.props.modal,"p-dialog-visible":this.state.maskVisible,"p-dialog-draggable":this.props.draggable,"p-dialog-resizable":this.props.resizable},this.props.maskClassName,this.getPositionClass()),o=this.renderHeader(),r=this.renderContent(),l=this.renderFooter(),d=this.renderResizer();return e.createElement("div",{ref:function(e){return t.mask=e},style:this.props.maskStyle,className:n,onClick:this.onMaskClick},e.createElement(a,{nodeRef:this.dialogRef,classNames:"p-dialog",timeout:{enter:"center"===this.props.position?150:300,exit:"center"===this.props.position?150:300},in:this.state.visible,options:this.props.transitionOptions,unmountOnExit:!0,onEnter:this.onEnter,onEntered:this.onEntered,onExiting:this.onExiting,onExited:this.onExited},e.createElement("div",{ref:this.dialogRef,id:this.state.id,className:i,style:this.props.style,onClick:this.props.onClick,role:"dialog","aria-labelledby":this.state.id+"_header","aria-describedby":this.state.id+"_content","aria-modal":this.props.modal},o,r,l,d)))}},{key:"render",value:function(){if(this.state.maskVisible){var t=this.renderElement();return e.createElement(d,{element:t,appendTo:this.props.appendTo,visible:!0})}return null}}])&&b(w.prototype,S),L&&b(w,L),Object.defineProperty(w,"prototype",{writable:!1}),C}();L={id:null,header:null,footer:null,visible:!1,position:"center",draggable:!0,resizable:!0,modal:!0,onHide:null,onShow:null,contentStyle:null,contentClassName:null,closeOnEscape:!0,dismissableMask:!1,rtl:!1,closable:!0,style:null,className:null,maskStyle:null,maskClassName:null,showHeader:!0,appendTo:null,baseZIndex:0,maximizable:!1,blockScroll:!1,icons:null,ariaCloseIconLabel:"Close",focusOnShow:!0,minX:0,minY:0,keepInViewport:!0,maximized:!1,breakpoints:null,transitionOptions:null,onMaximize:null,onDragStart:null,onDrag:null,onDragEnd:null,onResizeStart:null,onResize:null,onResizeEnd:null,onClick:null,onMaskClick:null},(S="defaultProps")in(w=R)?Object.defineProperty(w,S,{value:L,enumerable:!0,configurable:!0,writable:!0}):w[S]=L;export{R as Dialog};