import{j as r,at as w,W as f}from"./vendor-mui-core-DnR6WYuU.js";import{r as d}from"./vendor-react-CTtPmzVP.js";import{n as U,C as F,a4 as q,ak as G,A as H}from"./vendor-utils-D5UG1a5Y.js";import{V,Q as D}from"./vendor-ux-DMZIE6wA.js";import{S as M}from"./index-lK6Pf_qM.js";import{a as Y}from"./page-header-CHAwrgX-.js";import{y as z,af as Q,J as a,c as W,q as B}from"./index-DwyzCfdd.js";import{S as $}from"./layout-tkk_Lr2y.js";import{S as X}from"./step-actions-AHe2MQxo.js";import{S as J}from"./button-BnSiFtNt.js";import"./vendor-hooks-BZ19vVZ7.js";import"./lottie-web-4koyQiv_.js";import"./Google-DA3WTnLE.js";import"./cloneDeep-B_fYlLpl.js";import"./create-passport-svg-DGPNsGUE.js";import"./vendor-arcblock-DkdOhPyM.js";import"./required-BQln5OcV.js";import"./form-wrapper-PT5ZzMQy.js";import"./logo-uploader-TLOlwvRt.js";import"./collapse-B7gUzFaX.js";import"./content-layout-DmSBGGVm.js";import"./use-mobile-D5clNlrm.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,C]=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"),C(!0)):(c.current!=="scroll"&&(m("scroll"),c.current="scroll"),C(!1))),t=null},50))};let p;return window.ResizeObserver?p=new ResizeObserver(u):window.addEventListener("resize",u),p.observe(i.current),p.observe(l.current),()=>{p?p.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:f.any,bottom:f.element.isRequired,onBottomFix:f.func};function ee({onNext:h=()=>{},onPrevious:O=()=>{},buttonText:m=""}){const{t:i}=V(),[l,E]=d.useState(!1),[c,L]=d.useState(null),{did:C,blocklet:t,actions:u}=z(),{prefix:p,getSessionInHeader:R}=Q();let _=(t.configs||[]).filter(e=>!a.BLOCKLET_CONFIGURABLE_KEY[e.key]);const T=t.environments.find(e=>e.key==="BLOCKLET_PASSPORT_COLOR"),S=F(W.WELLKNOWN_SERVICE_PATH_PREFIX,`/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:C,prefix:p,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:T?T.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=q(G([..._,...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(g){D.error(g.message)}finally{E(!1)}},v={},I=[...P,...K].reduce((e,o)=>{const{value:n,...s}=o;v[o.key]=n;const g=n?n.match(a.BLOCKLET_AUTOMATIC_ENV_VALUE_REGEX):null;if(g!==null||n===a.BLOCKLET_AUTOMATIC_ENV_VALUE){let y=e.find(x=>x.componentType==="collapse");return y||(y={key:"BLOCKLET_CONFIG_COLLAPSE",description:i("blocklet.config.advanced"),componentType:"collapse",children:[]}),g!==null&&(s.hidden=!0),y.children.push({...s}),[...e.filter(x=>x.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($,{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(X,{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:f.string,onNext:f.func,onPrevious:f.func};export{ee as default};
