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