import{R as e,$ as t,S as n,L as l,a as s,T as i,w as o,U as r,f as a,i as c,V as d,W as u,j as f,D as p,G as v,X as m,k as x,l as g,m as j,n as h,o as b,g as y,t as k,u as C}from"../../vendor.js";import{forwardRef as N,useMemo as E,useReducer as F,useEffect as S,useCallback as D}from"react";import"react-popper";import"react-dom";import{u as O,a as R,b as T}from"../../hooks.js";import{D as z,a as w,b as G}from"../../defaults.js";import{T as L}from"../Text/index.js";import{F as U}from"./Field.js";function V(e,t){var n=k(e);if(C){var l=C(e);t&&(l=a(l).call(l,(function(t){return b(e,t).enumerable}))),n.push.apply(n,l)}return n}function W(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?V(Object(n),!0).forEach((function(t){x(e,t,n[t])})):g?j(e,g(n)):V(Object(n)).forEach((function(t){h(e,t,b(n,t))}))}return e}var X=N((function(x,g){var j,h,b=x.element,k=x.component,C=x.styles,N=x.attributes,V=x.popper,X=x.onSave,$=x.onCancel,q=O(),A=q.setElement,B=q.overrides,H=q.getOverrides,I=R(),J=E((function(){var l,s,i,o,r,a,c,d,u,f;return[e({},!1!==(null===(l=k.settings)||void 0===l||null===(s=l.defaults)||void 0===s?void 0:s.settings)?n(G):{},t(k.settings||{},["defaults","styling","responsive"]),{title:function(e){return e("core.settings.title","Settings")}},t(I.settings||{},["defaults","styling","responsive"])),e({},!1!==(null===(i=k.settings)||void 0===i||null===(o=i.defaults)||void 0===o?void 0:o.styling)?n(z):{},(null===(r=k.settings)||void 0===r?void 0:r.styling)||{},(null===(a=I.settings)||void 0===a?void 0:a.styling)||{}),e({},!1!==(null===(c=k.settings)||void 0===c||null===(d=c.defaults)||void 0===d?void 0:d.responsive)?n(w):{},(null===(u=k.settings)||void 0===u?void 0:u.responsive)||{},(null===(f=I.settings)||void 0===f?void 0:f.responsive)||{})]}),[B]),K=F(l,{element:{}}),M=s(K,2),P=M[0],Q=M[1];S((function(){Q({element:ee(n(b))})}),[b]),T((function(){Q({element:ee(P.element)})}),[B]);var Y=D((function(e){var t,n;return null===(t=e?null==e?void 0:e.fields:i(n=o(J).call(J,(function(e){return e.fields}))).call(n))||void 0===t?void 0:r(t).call(t,(function(e,t){return(t.priority||0)-(e.priority||0)}))}),[J,B]),Z=D((function(){var e,t;return a(e=o(t=Y()).call(t,(function(e){return[e.key,e.type]}))).call(e,(function(e){return e[0]}))}),[Y]),_=function(e,t){var l;return c(l=Z()).call(l,(function(e,n){var l=s(n,2),i=l[0],o=l[1],r=H("component",b.type,{output:"field",field:{key:i,type:o}}),a=d(e,i);return"function"==typeof r[t]&&a&&u(e,i,r[t](a)),e}),n(e))},ee=function(e){return _(e,"deserialize")},te=function(e){Q({element:e})},ne=function(e,t){var n;u(P.element,e,null!==(n=t.checked)&&void 0!==n?n:t.value),Q({element:P.element})},le=function(e,t,n){var l=t.onChange(e,n,P.element);Q({element:y(P.element,l)})};return f.exports.jsxs("div",W(W({ref:g,style:C.popper},N.popper),{},{className:"oak-editable",children:[f.exports.jsx("div",{className:"oak-title",children:null!==(j=k.settings)&&void 0!==j&&j.title?f.exports.jsx(L,{children:null===(h=k.settings)||void 0===h?void 0:h.title}):f.exports.jsx(L,{name:"core.components.default.settings.title",default:"Element options"})}),f.exports.jsxs("div",{className:"oak-form",children:[f.exports.jsx(p,{children:o(J).call(J,(function(e,t){var l,s,i;return f.exports.jsxs(v,{title:f.exports.jsx(L,{children:e.title}),children:[null===(l=Y(e))||void 0===l||null===(s=a(l).call(l,(function(e){return!e.condition||e.condition(P.element)})))||void 0===s?void 0:o(s).call(s,(function(e,t){var n;return f.exports.jsxs("div",{className:"oak-field",children:[e.label&&f.exports.jsx("label",{children:f.exports.jsx(L,{children:e.label})}),e.fields?f.exports.jsx("div",{className:"oak-fields",children:o(n=e.fields).call(n,(function(e,t){return f.exports.jsxs("div",{className:"oak-field",children:[e.label&&f.exports.jsx("label",{className:"oak-field-label",children:f.exports.jsx(L,{children:e.label})}),f.exports.jsx(U,{field:e,editableRef:V,element:P.element,onChange:ne,onCustomChange:le})]},t)}))}):f.exports.jsx(U,{field:e,editableRef:V,element:P.element,onChange:ne,onCustomChange:le})]},t)})),null==e||null===(i=e.renderForm)||void 0===i?void 0:i.call(e,{element:n(P.element),component:k,update:te})]},t)}))}),f.exports.jsxs("div",{className:"oak-editable-buttons",children:[f.exports.jsx("a",{href:"#",onClick:function(e){e.preventDefault(),Q({element:ee(n(b))}),$()},children:f.exports.jsx(L,{default:"Cancel",name:"core.settings.cancel"})}),f.exports.jsx(m,{className:"primary",onClick:function(){var e;A(b,(e=P.element,_(e,"serialize"))),X()},children:f.exports.jsx(L,{default:"Save",name:"core.settings.save"})})]})]})]}))}));export{X as F};
//# sourceMappingURL=Form.js.map
