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