import e from"../../../@babel/runtime/helpers/esm/extends.js";import*as o from"react";import"../../../prop-types/index.js";import{FOCUS_DISABLED as t,FOCUS_GROUP as r}from"../../../focus-lock/dist/es2015/constants.js";import{hiddenGuard as s}from"./FocusGuard.js";import{mediumFocus as n,mediumBlur as a,mediumSidecar as c}from"./medium.js";import{useMergeRefs as u}from"../../../use-callback-ref/dist/es2015/useMergeRef.js";import{p as i}from"../../../../_virtual/index.js_commonjs-module";var d=[],l=o.forwardRef((function(i,l){var p,f=o.useState(),m=f[0],v=f[1],x=o.useRef(),b=o.useRef(!1),F=o.useRef(null),k=i.children,y=i.disabled,g=i.noFocusGuards,h=i.persistentFocus,j=i.crossFrame,E=i.autoFocus,w=i.allowTextSelection,C=i.group,N=i.className,R=i.whiteList,T=i.shards,D=void 0===T?d:T,L=i.as,S=void 0===L?"div":L,O=i.lockProps,P=void 0===O?{}:O,A=i.sideCar,G=i.returnFocus,_=i.onActivation,I=i.onDeactivation,M=o.useState({})[0],B=o.useCallback((function(){F.current=F.current||document&&document.activeElement,x.current&&_&&_(x.current),b.current=!0}),[_]),V=o.useCallback((function(){b.current=!1,I&&I(x.current)}),[I]),q=o.useCallback((function(e){var o=F.current;if(Boolean(G)&&o&&o.focus){var t="object"==typeof G?G:void 0;F.current=null,e?Promise.resolve().then((function(){return o.focus(t)})):o.focus(t)}}),[G]),z=o.useCallback((function(e){b.current&&n.useMedium(e)}),[]),H=a.useMedium,J=o.useCallback((function(e){x.current!==e&&(x.current=e,v(e))}),[]);"production"!==process.env.NODE_ENV&&(void 0!==w&&console.warn("React-Focus-Lock: allowTextSelection is deprecated and enabled by default"),o.useEffect((function(){x.current||console.error("FocusLock: could not obtain ref to internal node")}),[]));var K=e(((p={})[t]=y&&"disabled",p[r]=C,p),P),Q=!0!==g,U=Q&&"tail"!==g,W=u([l,J]);return o.createElement(o.Fragment,null,Q&&[o.createElement("div",{key:"guard-first","data-focus-guard":!0,tabIndex:y?-1:0,style:s}),o.createElement("div",{key:"guard-nearest","data-focus-guard":!0,tabIndex:y?-1:1,style:s})],!y&&o.createElement(A,{id:M,sideCar:c,observed:m,disabled:y,persistentFocus:h,crossFrame:j,autoFocus:E,whiteList:R,shards:D,onActivation:B,onDeactivation:V,returnFocus:q}),o.createElement(S,e({ref:W},K,{className:N,onBlur:H,onFocus:z}),k),U&&o.createElement("div",{"data-focus-guard":!0,tabIndex:y?-1:0,style:s}))}));l.propTypes="production"!==process.env.NODE_ENV?{children:i.exports.node,disabled:i.exports.bool,returnFocus:i.exports.oneOfType([i.exports.bool,i.exports.object]),noFocusGuards:i.exports.bool,allowTextSelection:i.exports.bool,autoFocus:i.exports.bool,persistentFocus:i.exports.bool,crossFrame:i.exports.bool,group:i.exports.string,className:i.exports.string,whiteList:i.exports.func,shards:i.exports.arrayOf(i.exports.any),as:i.exports.oneOfType([i.exports.string,i.exports.func,i.exports.object]),lockProps:i.exports.object,onActivation:i.exports.func,onDeactivation:i.exports.func,sideCar:i.exports.any.isRequired}:{},l.defaultProps={children:void 0,disabled:!1,returnFocus:!1,noFocusGuards:!1,autoFocus:!0,persistentFocus:!1,crossFrame:!0,allowTextSelection:void 0,group:void 0,className:void 0,whiteList:void 0,shards:void 0,as:"div",lockProps:{},onActivation:void 0,onDeactivation:void 0};export default l;
//# sourceMappingURL=Lock.js.map
