import{n as e,P as n,$ as t,a0 as s,a1 as l,j as o,X as i,L as a,Y as r,a2 as d,R as c,f as p,_ as u,g as f,d as m,a as v,c as x,a3 as g,u as j,k as h,i as b,l as k}from"../../vendor.js";import{createPortal as C}from"react-dom";import{forwardRef as y,useState as N,useReducer as S,useEffect as E,useImperativeHandle as F,cloneElement as R,Children as O}from"react";import{usePopper as D}from"react-popper";import{a as T,u as _}from"../../hooks.js";import{D as w,a as B,b as H}from"../../defaults.js";import{T as L}from"../Text/index.js";import{F as P}from"./Field.js";function X(e,n){var t=h(e);if(b){var s=b(e);n&&(s=k(s).call(s,(function(n){return x(e,n).enumerable}))),t.push.apply(t,s)}return t}function Y(e){for(var n=1;n<arguments.length;n++){var t,s=null!=arguments[n]?arguments[n]:{};if(n%2)p(t=X(Object(s),!0)).call(t,(function(n){u(e,n,s[n])}));else if(f)m(e,f(s));else{var l;p(l=X(Object(s))).call(l,(function(n){v(e,n,x(s,n))}))}}return e}var $=y((function(p,u){var f,m,v,x,h,b,k,y,X,$,q,z,A,G=p.children,I=p.element,J=p.component,K=T(),M=K.setElement,Q=K._settingsHolderRef,U=_(),V=N(),W=e(V,2),Z=W[0],ee=W[1],ne=N(),te=e(ne,2),se=te[0],le=te[1],oe=S(n,{opened:!1,element:t(I)}),ie=e(oe,2),ae=ie[0],re=ie[1];E((function(){re({element:t(I)})}),[I]);var de=D(se,Z,Y({},("function"==typeof(null==J||null===(f=J.settings)||void 0===f?void 0:f.popperSettings)?null==J||null===(m=J.settings)||void 0===m?void 0:m.popperSettings({optionButtonElement:se}):null==J||null===(v=J.settings)||void 0===v?void 0:v.popperSettings)||{modifiers:[{name:"preventOverflow",options:{boundary:!0}},{name:"offset",options:{offset:[0,5]}}]})),ce=de.styles,pe=de.attributes;F(u,(function(){return{open:ue,close:fe,toggle:me}}));var ue=function(){re({opened:!0})},fe=function(){re({opened:!1})},me=function(){return ae.opened?fe():ue()},ve=function(e){M(I,e)},xe=function(e,n){var t;g(ae.element,e,null!==(t=n.checked)&&void 0!==t?t:n.value),re({element:ae.element})},ge=function(e,n,t){var s=n.onChange(e,t,ae.element);re({element:j(ae.element,s)})},je=[s({},!1!==(null===(x=J.settings)||void 0===x||null===(h=x.defaults)||void 0===h?void 0:h.settings)?t(w):{},l(J.settings||{},["defaults","styling","responsive"]),{title:function(e){return e("core.settings.title","Settings")}}),s({},!1!==(null===(b=J.settings)||void 0===b||null===(k=b.defaults)||void 0===k?void 0:k.styling)?t(B):{},(null===(y=J.settings)||void 0===y?void 0:y.styling)||{}),s({},!1!==(null===(X=J.settings)||void 0===X||null===($=X.defaults)||void 0===$?void 0:$.responsive)?t(H):{},(null===(q=J.settings)||void 0===q?void 0:q.responsive)||{})],he=o.exports.jsxs("div",Y(Y({ref:ee,style:ce.popper},pe.popper),{},{className:"oak-editable",children:[o.exports.jsx("div",{className:"oak-title",children:null!==(z=J.settings)&&void 0!==z&&z.title?o.exports.jsx(L,{children:null===(A=J.settings)||void 0===A?void 0:A.title}):o.exports.jsx(L,{name:"core.components.default.settings.title",default:"Element options"})}),o.exports.jsxs("div",{className:"oak-form",children:[o.exports.jsx(i,{children:a(je).call(je,(function(e,n){var s,l;return o.exports.jsxs(r,{title:o.exports.jsx(L,{children:e.title}),children:[null==e||null===(s=e.fields)||void 0===s?void 0:a(s).call(s,(function(e,n){var t;return(!e.condition||e.condition(ae.element))&&o.exports.jsxs("div",{className:"oak-field",children:[e.label&&o.exports.jsx("label",{children:o.exports.jsx(L,{children:e.label})}),e.fields?o.exports.jsx("div",{className:"oak-fields",children:a(t=e.fields).call(t,(function(e,n){return o.exports.jsx("div",{className:"oak-field",children:o.exports.jsx(P,{field:e,editableRef:Z,element:ae.element,onChange:xe,onCustomChange:ge})},n)}))}):o.exports.jsx(P,{field:e,editableRef:Z,element:ae.element,onChange:xe,onCustomChange:ge})]},n)})),null==e||null===(l=e.renderForm)||void 0===l?void 0:l.call(e,{element:t(I),component:J,update:ve})]},n)}))}),o.exports.jsxs("div",{className:"oak-editable-buttons",children:[o.exports.jsx("a",{href:"#",onClick:function(e){e.preventDefault(),re({element:t(I)}),fe()},children:o.exports.jsx(L,{default:"Cancel",name:"core.settings.cancel"})}),o.exports.jsx(d,{className:"primary",onClick:function(){M(I,ae.element),fe()},children:o.exports.jsx(L,{default:"Save",name:"core.settings.save"})})]})]})]}));return o.exports.jsxs(o.exports.Fragment,{children:[G&&R(O.only(G),{ref:le,className:c(O.only(G).props.className,{"oak-opened":ae.opened})}),ae.opened?U.settingsContainer||Q?C(he,U.settingsContainer||Q):he:null]})}));export{$ as E};
//# sourceMappingURL=index.js.map
