"use strict";var e=require("../focus-DdgBlQbB.js"),r=require("./overlayManager.js"),s=require("./overlayUtils.js");require("./tooltipLibrary.js"),require("@kdcloudjs/kwc"),require("./positionLibrary.js"),require("../observable-BXDJFaLN.js"),require("../empty_html-hFq4zm9t.js"),require("../i18n-CP31jeWH.js"),require("../normalize-DKPi18vK.js"),require("./utilsPrivate.js"),require("../client-Co_j5m_k.js"),require("../ssr-RXknEJpO.js"),require("./iso8601Utils.js"),require("../colorValid-BBnkvgd_.js"),require("./primitiveBubble.js"),require("../kddsCommon-CICoPypw.js"),require("./shadowBaseClassPrivate.js"),require("../classSet-B5xuJbNb.js"),require("./ariaObserver.js");const t=["lightning-modal-header","lightning-modal-body","lightning-modal-footer","lightning-focus-trap","lightning-overlay-container"];exports.modalFocusinEventHandler=function(i){const{isModalClosing:o,lastFocusedElement:l}=this;if(!r.isKwcModalActive()||o)return;let a=null;i.target&&"function"==typeof i.target.closest?a=i.target.closest(t.join(",")):i.relatedTarget&&"function"==typeof i.relatedTarget.closest&&(a=i.relatedTarget.closest(t.join(","))),a?(this.lastFocusedElement=e.getElementWithFocus(),this.dispatchEvent(new CustomEvent("privatelightningmodallastfocus",{composed:!0,bubbles:!0,detail:{[s.secure]:!0,privatelightningmodallastfocus:this.lastFocusedElement}}))):l&&(l.ariaHasPopup||e.returnFocusToElement(l))};
