import{j as r,aT as w,X as p}from"./vendor-mui-core-CDEc-eG6.js";import{r as d}from"./vendor-react-DX7tU9aY.js";import{n as U,y as F,a4 as G,an as q,x as H}from"./vendor-utils-_C9URqjS.js";import{aa as V,a3 as D}from"./vendor-ux-PO0jFgJf.js";import{S as M}from"./index-CZWagtq4.js";import{a as Y}from"./page-header-CEL5h6do.js";import{v as z,a5 as W,F as a,W as X,n as B}from"./index-CgSpL7jz.js";import{S as Q}from"./layout-DkUZePxy.js";import{S as $}from"./step-actions-Ezqn_AMv.js";import{S as J}from"./button-BdkIS-Qs.js";import"./vendor-hooks-Ca2cSNuD.js";import"./Google-BpkBLSiL.js";import"./cloneDeep-D_udiNLL.js";import"./create-passport-svg-DNOT-xbE.js";import"./vendor-arcblock-BVQTtbN-.js";import"./required-BO8emcue.js";import"./form-wrapper-BqPFgoVY.js";import"./logo-uploader-CEZXDf8O.js";import"./collapse-DRkXbQaT.js";import"./content-layout-D49-hpq6.js";import"./use-mobile-DUKvJoqs.js";function A({children:h=[],bottom:O,onBottomFix:m=U}){const i=d.useRef(null),l=d.useRef(null),E=d.useRef(null),c=d.useRef(null),[L,g]=d.useState(!1);return d.useEffect(()=>{let t;const u=()=>{t||(t=setTimeout(()=>{l.current&&(l.current.scrollHeight>i.current.clientHeight-E.current.clientHeight?(c.current!=="fix"&&(m("fix"),c.current="fix"),g(!0)):(c.current!=="scroll"&&(m("scroll"),c.current="scroll"),g(!1))),t=null},50))};let f;return window.ResizeObserver?f=new ResizeObserver(u):window.addEventListener("resize",u),f.observe(i.current),f.observe(l.current),()=>{f?f.disconnect():window.removeEventListener("resize",u),t&&clearTimeout(t)}},[m]),r.jsxs(Z,{ref:i,className:`${L?"scroll-mode":""}`,children:[r.jsx("div",{className:"compact-context",ref:l,children:h}),r.jsx("div",{className:"fix-container",ref:E,children:O})]})}const Z=w.div`
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  animation: fadein ease 0.5s;

  .fix-container {
    margin-top: auto;
    width: 100%;
  }

  &.scroll-mode {
    .compact-context {
      flex: 1;
      overflow-y: auto;
    }
    .fix-container {
      margin-top: auto;
      flex-shrink: 0;
    }
  }

  @keyframes fadein {
    0% {
      opacity: 0;
    }
    100% {
      opacity: 1;
    }
  }
`;A.propTypes={children:p.any,bottom:p.element.isRequired,onBottomFix:p.func};function ee({onNext:h=()=>{},onPrevious:O=()=>{},buttonText:m=""}){const{t:i}=V(),[l,E]=d.useState(!1),[c,L]=d.useState(null),{did:g,blocklet:t,actions:u}=z(),{prefix:f,getSessionInHeader:R}=W();let _=(t.configs||[]).filter(e=>!a.BLOCKLET_CONFIGURABLE_KEY[e.key]);const x=t.environments.find(e=>e.key==="BLOCKLET_PASSPORT_COLOR"),S=F(X,`/blocklet/logo?v=${t?.updatedAt}`),P=[{key:a.BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_LOGO_SQUARE,description:i("blocklet.config.logoSquare"),value:t.environments.find(e=>e.key==="BLOCKLET_APP_LOGO_SQUARE")?.value,componentType:"uploader",skipButtonDisabled:!0,solo:!0,componentProps:{url:S,height:120,width:120,type:"square",did:g,prefix:f,headers:R,onUploaded:u.refreshBlocklet}},{key:a.BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_NAME,description:i("blocklet.config.name"),value:t.environments.find(e=>e.key==="BLOCKLET_APP_NAME").value},{key:a.BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_DESCRIPTION,description:i("blocklet.config.description"),value:t.environments.find(e=>e.key==="BLOCKLET_APP_DESCRIPTION").value},{key:a.BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_PASSPORT_COLOR,description:i("blocklet.config.passportColor"),value:x?x.value:"auto",hidden:!0,componentType:"passport",componentProps:{blocklet:t}}],k=[];B.forEachChildSync(t,(e,{ancestors:o})=>{const n=o.slice(1).map(s=>s.meta.did);k.push((e.configs||[]).map(s=>({...s,childDid:n.concat(e.meta.did)})))}),t.meta.group===a.BlockletGroup.gateway&&(_=_.filter(e=>!e.secure&&e.shared));const K=G(q([..._,...k]),"key").filter(e=>!!e.key).sort((e,o)=>e.required&&!o.required?-1:o.required&&!e.required?1:0),N=B.getAppMissingConfigs(t).length,b=async e=>{const{childDid:o,...n}=c,s=[{...H(n,["key","value","description"]),value:e}];try{E(!0),await u.configBlocklet({configs:s,childDid:o})}catch(C){D.error(C.message)}finally{E(!1)}},v={},I=[...P,...K].reduce((e,o)=>{const{value:n,...s}=o;v[o.key]=n;const C=n?n.match(a.BLOCKLET_AUTOMATIC_ENV_VALUE_REGEX):null;if(C!==null||n===a.BLOCKLET_AUTOMATIC_ENV_VALUE){let y=e.find(T=>T.componentType==="collapse");return y||(y={key:"BLOCKLET_CONFIG_COLLAPSE",description:i("blocklet.config.advanced"),componentType:"collapse",children:[]}),C!==null&&(s.hidden=!0),y.children.push({...s}),[...e.filter(T=>T.componentType!=="collapse"),y]}return e.push({...s}),e},[]).map(e=>{if(e.componentType==="collapse"){const o=e.children.every(n=>n.hidden===!0);return{...e,hidden:o}}return e}),j=()=>{O()};return r.jsxs(Q,{children:[r.jsx("div",{className:"header",style:{marginBottom:16},children:r.jsx(Y,{title:i("setup.config.title"),subTitle:i("setup.config.subTitle"),onClickBack:j})}),r.jsx("div",{className:"container-main",children:r.jsx("div",{className:"container-inner",children:r.jsx(A,{bottom:r.jsx($,{mt:8,disabled:l||c,blocklet:t,onStartNow:()=>h("complete"),children:r.jsx(J,{variant:"contained",disabled:l||N||c,onClick:()=>{u.refreshFuel({showError:!1}),h()},children:m||i("setup.next")})}),children:r.jsx(M,{style:{margin:"0 auto 20px"},loading:l,schema:I,defaultValue:v,onChange:(e,{action:o,currentItem:n})=>{o==="edit"?L(n):["cancel","confirm"].includes(o)&&L(null),o==="confirm"&&b(e[n.key])}})})})})]})}ee.propTypes={buttonText:p.string,onNext:p.func,onPrevious:p.func};export{ee as default};
