import{a as e,b as n,D as o,$ as t,N as a,E as l,_ as i,a0 as r,a1 as s,a2 as u,F as c,G as p,S as d,m as f,A as m,n as v,o as g,q as b,r as h,s as y,a3 as j,y as k,z as x,g as C}from"../../vendor.js";import{forwardRef as E,useReducer as F,useMemo as P,useImperativeHandle as S,Children as w,cloneElement as O}from"react";import{createPortal as R}from"react-dom";import{u as N,a as _}from"../../hooks.js";import{F as q}from"./Form.js";function z(e,n){var o=k(e);if(x){var t=x(e);n&&(t=C(t).call(t,(function(n){return y(e,n).enumerable}))),o.push.apply(o,t)}return o}function A(e){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?z(Object(o),!0).forEach((function(n){v(e,n,o[n])})):g?b(e,g(o)):z(Object(o)).forEach((function(n){h(e,n,y(o,n))}))}return e}var B=E((function(v,g){var b,h,y,k=v.children,x=v.element,C=v.component,E=v.onToggle,z=N(),B=z._settingsHolderRef,D=z.oakRef,G=_(),H=F(e,{opened:!1,visible:!1}),M=n(H,2),T=M[0],$=M[1],I=P((function(){var e,n;return("function"==typeof(null==C||null===(e=C.settings)||void 0===e?void 0:e.floatingSettings)?C.settings.floatingSettings({optionButtonElement:Q}):null==C||null===(n=C.settings)||void 0===n?void 0:n.floatingSettings)||{}}),[C]),J=o({open:T.opened,onOpenChange:function(e){return e?ee():ne()},whileElementsMounted:t,placement:I.placement||"bottom",middleware:a(b=[l(5)]).call(b,i(!1!==(null==I||null===(h=I.shift)||void 0===h?void 0:h.enabled)?[r(A({boundary:null==D?void 0:D.current,limiter:s()},I.shift||{}))]:[]),i(!1!==(null==I||null===(y=I.autoPlacement)||void 0===y?void 0:y.enabled)?[u(A({boundary:null==D?void 0:D.current,allowedPlacements:["bottom","top"]},I.autoPlacement||{}))]:[]),i(I.middleware||[]))}),K=J.x,L=J.y,Q=J.reference,U=J.floating,V=J.strategy,W=J.context,X=c([p(W)]),Y=X.getReferenceProps,Z=X.getFloatingProps;S(g,(function(){return{open:ee,close:ne,toggle:oe}})),d((function(){$({opened:!0})}),1,[T.visible],{enabled:T.visible}),d((function(){$({visible:!1})}),100,[T.opened],{enabled:!T.opened});var ee=function(){$({visible:!0}),null==E||E({opened:!0})},ne=function(){$({opened:!1}),null==E||E({opened:!1})},oe=function(){return T.opened?ne():ee()},te=function(){return T.visible&&f.jsx("div",A(A({style:{position:V,top:null!=L?L:0,left:null!=K?K:0},"data-placement":W.placement,ref:U},Z()),{},{children:j(f.jsx(q,{element:x,component:C,placement:W.placement,onSave:ne,onCancel:ne}),{opened:T.opened})}))},ae=w.only(k);return f.jsxs(f.Fragment,{children:[ae&&O(ae,A({ref:function(e){Q(null!=e&&e.isOak?e.innerRef.current:e)},className:m(ae.props.className,{"oak-opened":T.opened})},Y({onClick:ae.props.onClick}))),G.settingsContainer||B?R(te(),G.settingsContainer||B):te()]})}));export{B as E};
//# sourceMappingURL=index.js.map
