import{parseFragment as e,registerTemplate as t,freezeTemplate as s,registerDecorators as o,registerComponent as n,createElement as r}from"@kdcloudjs/kwc";import i from"./shadowBaseClassPrivate.js";import{parent as l,instanceName as a,normalizeApis as d}from"./overlayUtils.js";import"../observable-tloG64m6.js";import"../i18n-B98kiI7M.js";import{g as c}from"../utilsPrivate-CI3EeA5x.js";import{addOverlayToSharedState as m,normalizeOverlayDetails as p,removeOverlayFromSharedState as h,subscribeOverlay as f,KWC_OVERLAY_TYPES as u,getStatCount as v,KWC_OVERLAY_ENGINE as y,KWC_TOAST_CONTAINER_STARTING_ZINDEX as k,KWC_OVERLAY_STARTING_ZINDEX as w,KWC_ZINDEX_OFFSET as C,KWC_ZINDEX_INCREMENT as j,TYPE_TOAST_CONTAINER as g}from"./overlayManager.js";import"../client-Ddi3i8XR.js";import"../ssr-C2pjZzfv.js";import"../empty_html-CjXB8rB4.js";import"./iso8601Utils.js";import"../colorValid-qIPgkqGp.js";const x=e`<div data-overlay-container lwc:dom="manual"${3}></div>`;function E(e,t,s,o){const{st:n}=e;return[n(x,1)]}var I=t(E);E.stylesheets=[],E.stylesheetToken="kwc-58h0h15lhrn",E.legacyStylesheetToken="D:\\new_workspace\\workspace\\kingdee-base-components\\src\\modules\\kd\\overlayContainer-undefined_overlayContainer",s(E);class N extends i{constructor(...e){super(...e),this.stack=[],this.afterFirstRender=!1}get root(){return this.template.querySelector("[data-overlay-container]")}push(e,t){if("object"!=typeof(t=t||{}))throw new Error("Invalid .open() or .open({}) argument.");if("innerHTML"in t||"outerHTML"in t)throw new Error("Illegal api values");const{[a]:s,[l]:o}=e;if(!this.isOverlayAllowedToAdd(s))return Promise.reject();const n=r(s,{is:e}),i=d(t);Object.entries(i).forEach(([e,t])=>{const s=e.toLowerCase().match(/^on(.+)/);if(s){const e=s[1];n.addEventListener(e,t)}else n[e]=t});let h=null;const f=c();if(o){const e=r(o[a],{is:o});this.root.appendChild(e),e.defaultSlot.appendChild(n),h=new Promise(t=>{this.stack.push({resolve:t,element:n,parentElement:e,id:f})})}else this.root.appendChild(n),h=new Promise(e=>{this.stack.push({resolve:e,element:n,id:f})});const u=p(y,s,{id:f});return m(u),h}findElementInStack(e){return this.stack.find(t=>t.element===e)}findElementIndexInStack(e){return this.stack.indexOf(t=>t.element===e)}pop(e,t,s){const o=this.findElementInStack(e);if(o&&!o.isClosing){o.isClosing=!0;const{element:e,parentElement:n,resolve:r,id:i}=o;r(t),s?s.then(()=>{this.removeOverlay(e,n,i)}):this.removeOverlay(e,n,i)}return null}removeOverlay(e,t,s){const o=e&&e.tagName.toLowerCase();if(t){const{defaultSlot:e}=t;t.parentNode&&t.parentNode.removeChild(t),e&&e.firstElementChild&&e.removeChild(e.firstElementChild)}else e&&(e.parentNode?e.parentNode.removeChild(e):e.remove());const n=this.findElementIndexInStack(e);n>-1&&this.stack.splice(n,1);const r=p(y,o,{id:s});h(r)}connectedCallback(){f(this.afterFirstRender,e=>{const{mixedOverlayPresent:t,auraHighestZindex:s,lwcAllOverlayCount:o,stack:n}=e;if(0===o)return;let r=w,i=0;const l=k;n.forEach((o,n)=>{const{overlayEngine:a,overlayType:d,overlayDetails:c}=o;let m;const h=u[d]&&u[d].pos||"fixed",f=d===g;if(t)if(a===y){m=this.root.childNodes[i];const t=!(!c||!c.zIndex),o=c&&c.zIndex;let u;if(!t||Number.isNaN(o)){f?u=l:(r=0!==n?s+C:r,u=r);const t={zIndex:u},o=p(a,d,Object.assign({},c,t));null!==o&&(e.stack[n]=o)}else f?u=o>=k?o:k:(r=o>=w?o:w,u=r);m&&(m.style.zIndex=u,m.style.position=h,i+=1)}else r+=j;else if(m=this.root.childNodes[i],m){const t=f?l:r;m.style.zIndex=t,m.style.position=h;const s={zIndex:t},o=p(a,d,Object.assign({},c,s));null!==o&&(e.stack[n]=o),i+=1}})}),this.afterFirstRender=!0}isOverlayAllowedToAdd(e){if(!!!u[e])return!1;const{maxNum:t,statName:s}=u[e],o=void 0===t,n=s&&v(s)||0;return o||t>n}}o(N,{publicMethods:["push","pop"],fields:["stack","afterFirstRender"]});const b=n(N,{tmpl:I,sel:"D:\\new_workspace\\workspace\\kingdee-base-components\\src\\modules\\kd\\overlayContainer-",apiVersion:63});export{b as default};
