import{r as u}from"./vendor-react-CUXIiAnY.js";import{W as o,j as e,ak as j,aN as L,z as A,at as K,bn as B,I as P,a6 as W,bF as M,aj as X,bG as G}from"./vendor-mui-core-BPQ6AEW_.js";import{C as H}from"./Google-FE-PKKgg.js";import{p as U}from"./vendor-ux-r9bApERu.js";import{c as Y}from"./create-passport-svg-CIUyZVGt.js";import{A as $}from"./vendor-arcblock-D8WYBDYe.js";import{e as J}from"./index-DY2wgD65.js";import{R as Q}from"./required-Btg6mEmX.js";import{F as Z}from"./form-wrapper-CU8kJXy5.js";import{L as v}from"./logo-uploader-DY97Qerr.js";import{A as ee,a as ne,b as te}from"./collapse-CzqKk-Uw.js";const S={description:o.string,editing:o.bool,onChange:o.func,required:o.bool,value:o.any,componentProps:o.object,render:o.func,renderFormItem:o.func};function T({editing:n,value:s,onChange:l}){const[i,c]=u.useState(!1),m=u.useRef(),f=u.useRef(s);u.useEffect(()=>{let a=null;return n&&(a=setTimeout(()=>{c(!0)},50)),()=>{clearTimeout(a)}},[n]);const h=a=>{f.current=a,l(a)},b=()=>{c(!1),l(f.current)},y=e.jsx(j,{className:"form-item-input slot",sx:{px:1},children:e.jsxs(j,{sx:{display:"flex",alignItems:"center"},children:[s,s!=="auto"&&e.jsx("div",{style:{marginLeft:4,backgroundColor:s,width:"1em",height:"1em",borderRadius:"0.2em"}})]})}),p=e.jsxs(j,{onKeyDown:b,sx:{display:"flex",flexGrow:1,alignItems:"center",height:"40px"},children:[e.jsx(j,{onClick:()=>c(!0),sx:{display:"flex",alignItems:"center"},children:e.jsx("div",{ref:m,style:{flexShrink:0,marginLeft:"8px",backgroundColor:s,width:"32px",height:"32px",boxSizing:"border-box",borderRadius:"8px",border:"1px solid #eee",cursor:s==="auto"?"default":"pointer"}})}),e.jsx(L,{open:i,anchorEl:m.current,onClose:()=>c(!1),anchorOrigin:{vertical:"bottom",horizontal:"center"},transformOrigin:{vertical:"top",horizontal:"center"},children:e.jsx(H,{color:s,onChange:a=>h(a.hex)})})]});return n?p:y}T.propTypes=S;function D({editing:n,description:s,value:l,onChange:i,componentProps:c={},...m}){const{placeholder:f}=c,h=u.useRef(l),{t:b}=u.useContext(U),y=a=>{a.key==="Enter"&&i(h.current,"confirm")},p=a=>{h.current=a,i(a)};return n?e.jsx(A,{style:{flex:1},fullWidth:!0,value:l,onChange:a=>{a.persist(),p(a.target.value)},autoFocus:!0,size:"small",variant:"outlined",placeholder:s||f,onKeyDown:y,...m}):e.jsx(j,{className:"form-item-input slot",sx:{px:1},children:l||e.jsx("span",{className:"placeholder",children:b("common.requiredInputPlaceholder",{name:s||f})})})}D.propTypes=S;function O({editing:n,value:s,onChange:l,componentProps:i,...c}){const{blocklet:m}=i,f=s==="auto"?$(m.appDid):s;return e.jsxs(j,{sx:{display:"flex",alignItems:"center"},children:[e.jsx("div",{style:{width:96,marginRight:12},dangerouslySetInnerHTML:{__html:Y({title:"Owner",issuer:J.getDisplayName(m),issuerDid:m.appDid,ownerName:"Your Name",ownerDid:m.appDid,preferredColor:s||"auto"})}}),e.jsx(T,{...c,editing:n,value:n?f:s,onChange:l,componentProps:i})]})}O.propTypes={...S,componentProps:o.shape({blocklet:o.object.isRequired}).isRequired};const re=G`
  0%, 100% {
    transform: scale(1) translateX(0);
  }
  50% {
    transform: scale(1.05) translateX(-3px);
  }
  25%, 75% {
    transform: scale(1.1) translateX(3px);
  }
`,oe={input:D,color:T,passport:O,uploader:n=>e.jsx(v,{...n.componentProps})};function se(n,{editing:s=!1}){const{componentType:l="input",render:i,renderFormItem:c}=n;return s&&c?c:!s&&i?i:oe[l?.toLowerCase()]}V.propTypes={item:o.object.isRequired,findEditingItem:o.func.isRequired,getItemValue:o.func.isRequired,onFormItemChange:o.func.isRequired,onFocusOut:o.func.isRequired,disabled:o.bool,loading:o.bool,onCancel:o.func,formValues:o.object.isRequired};function V({item:n,findEditingItem:s,getItemValue:l,onFormItemChange:i,onFocusOut:c,disabled:m=!1,loading:f=!1,onCancel:h=()=>{},formValues:b}){const{key:y,description:p,required:a,solo:R=!1,hidden:g=!1,componentProps:C={},skipButtonDisabled:w=!1}=n;if(g)return null;const F=s(y),{editing:I,shaking:E}=F??{},q=l(n,{editing:I}),r=se(n,{editing:I}),t={inputProps:{"data-cy":"schema-form-item-component"},key:y,description:p,editing:I,value:q,onChange:(x,d="change")=>i(n,x,d),componentProps:C,skipButtonDisabled:w,onBlur:()=>c(n)};return n.componentType==="collapse"&&n.children?.length>0?e.jsxs(ee,{children:[e.jsx(ne,{expandIcon:e.jsx(B,{fontSize:"small"}),"aria-controls":"panel1-content",id:"panel1-header",children:n.description}),e.jsx(te,{children:n.children.map(x=>e.jsx(V,{item:x,findEditingItem:s,getItemValue:l,onFormItemChange:i,onFocusOut:c,formValues:b,disabled:m,loading:f,onCancel:h},x.key))})]}):e.jsxs(j,{className:"form-item",children:[!R&&e.jsxs(j,{className:"form-item-label",sx:{color:a&&!q?"error.main":"text.secondary"},children:[p,a&&e.jsx(Q,{})]}),e.jsxs(j,{className:"form-item-body",children:[e.jsx(j,{className:"form-item-input","data-cy":"schema-form-item-edit",sx:{textAlign:R?"center":"left"},style:{cursor:"text"},onClick:()=>{m||F?.edited||w||i(n,b[y],"edit")},children:e.jsx(r,{...t})}),!R&&e.jsx(j,{className:"form-item-action",style:{marginLeft:0},children:I?e.jsxs(e.Fragment,{children:[F.edited?e.jsx(P,{"data-cy":"schema-form-item-confirm",onClick:()=>{i(n,q,"confirm")},disabled:m||f,sx:{animation:E?`${re} 0.5s linear`:"none"},style:{paddingRight:4},size:"large",children:f?e.jsx(W,{size:24}):e.jsx(M,{})}):null,e.jsx(P,{"data-cy":"schema-form-item-cancel",onClick:()=>h(n),style:{paddingLeft:F.edited?4:8},disabled:m||f,size:"large",children:e.jsx(X,{})})]}):null})]})]},y)}function ie({schema:n,loading:s=!1,value:l=void 0,defaultValue:i={},onChange:c,style:m={},disabled:f=!1}){const h=Object.prototype.toString.call(l)==="[object Object]",[b,y]=u.useState([]),[p,a]=u.useState(h?l:i),R=u.useMemo(()=>n.length===1,[n]),g=u.useCallback(r=>b.find(t=>t.key===r),[b]);u.useEffect(()=>{R&&n[0]?.required&&y([{key:n[0].key,editing:!0,initialValue:i[n[0].key]}])},[n,R,i]);const C=u.useCallback(r=>{y(t=>t.find(d=>d.key===r.key)?t.map(d=>d.key===r.key?r:{...d}):[r].concat(t))},[]),w=u.useCallback((r,t,x)=>{const{key:d,secure:_}=r,k=g(d)??{...r};k.editing=!0;const z=p[d]!==t;k.edited=t&&k.initialValue!==t,k.initialValue=i[d];const N={...p,[d]:t};z&&a(N),c({[d]:t},{allValues:N,action:x,currentItem:r}),x==="confirm"&&_&&a({...p,[d]:"__encrypted__"}),x==="confirm"&&(k.initialValue=p[d]),["confirm","cancel"].includes(x)&&(k.editing=!1,k.edited=!1),C(k)},[i,p,c,C,g]),F=u.useCallback((r,{editing:t=!1})=>{const{key:x}=r,d=h?l[x]:p[x];return d==="__encrypted__"?t?"":"******":d},[h,l,p]),I=u.useCallback(r=>{const t=g(r.key);t&&w(r,t.initialValue,"cancel")},[g,w]),E=u.useCallback(r=>{const t=g(r.key);!t||!t.edited||(t.shaking=!0,C(t),setTimeout(()=>{t.shaking=!1,C(t)},500))},[g,C]),q=u.useCallback(r=>{const t=g(r.key);!t||!t.edited?I(r):E(r)},[g,E,I]);return e.jsx(ae,{className:"form",style:m,children:n?.map(r=>{const{hidden:t=!1}=r;return t?null:e.jsx(V,{item:r,findEditingItem:g,getItemValue:F,onFormItemChange:w,onFocusOut:q,formValues:p,disabled:f,loading:s,onCancel:I})})})}ie.propTypes={schema:o.array.isRequired,loading:o.bool,onChange:o.func.isRequired,value:o.object,defaultValue:o.object,style:o.object,disabled:o.bool};const ae=K(Z)``;export{ie as S};
