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