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