import{r as m,p as Be,j as e,C as J,Q as Te,q as M,o as A,b as me,V as X,d as Fe,ct as Ae,cu as De,cv as Ee,J as R,au as te,bz as K,A as Ie,D as Pe,x as Re,ao as _e,u as de,H as $,g as Le,bE as Ne,ab as ze,al as Ue,k as $e,b3 as Me,B as y,bM as se,bK as le,aU as N,bt as We,cw as z,ad as Oe,F as oe,aC as qe,S as ne,M as re,cx as Ve,at as ae,bB as He}from"./index-DR3HTfO6.js";import{u as Ke}from"./useLocalStorage-BUDMB9ci.js";import{E as Qe}from"./ErrorOutline-l3lhgB6z.js";import{g as Je,H as Xe}from"./index-DX1Rg408.js";import{y as Ge}from"./index-BlSr9ZCo.js";import{B as I,W as Ye}from"./status-BacQWMX9.js";import{D as Ze,u as et,B as ie}from"./actions-BKRupxTm.js";import{I as tt,B as st}from"./install-from-url-DIP6uEgr.js";import{u as ue}from"./url-evaluation-BsOpcqpZ.js";import{L as lt}from"./Launch-D7JOh1At.js";import{A as ot}from"./Add-lbPfahUt.js";import{O as P}from"./index-COWAzaDS.js";import{s as ce}from"./schema-DNQzbIYt.js";import{P as nt}from"./permission-DiBS4qUa.js";import"./FilterList-BduCnH7c.js";import"./CSSTransition--PBqXHt0.js";import"./emotion-cache.browser.esm-DHWVBIJA.js";import"./index-n5-asI58.js";import"./redux-Ab4buSXY.js";import"./typeof-QjJsDpFa.js";import"./depsEqual-CJ8pX2dq.js";import"./TableSearch-BCTie1Ve.js";import"./Search-DY52i3Q9.js";import"./Clear-DKF2FhrE.js";import"./MoreVert-B7vfcAq6.js";import"./DeleteOutline-B5g018fL.js";import"./get-safe-url-CU6gs6Gc.js";import"./ButtonGroup-BjIAZaBg.js";import"./getValidReactChildren-DB5-GZmu.js";import"./without-wallet-DVE74yMq.js";import"./index-C7jwWtcG.js";import"./login-method-item-D2kHRJFB.js";import"./passkey-rounded-_WDHIZVd.js";import"./cloneDeep-DJE0LHwI.js";import"./index-BM-Ox268.js";import"./Delete-DbU8Oz1h.js";import"./Autocomplete-Cvfgn0bq.js";import"./ListSubheader-CD838Q5u.js";import"./ListItemButton-C-exxs1G.js";import"./Stepper-DYUxfIu2.js";function Q({blocklet:j,skipAccessibilityCheck:f=!1,...d}){const{t:i}=m.useContext(Be),{urls:S,loading:r,recommendedUrl:g}=ue(j);if(r&&!f)return e.jsx(J,{size:12,...d});const x=f?S[0]:g;return x?e.jsx(at,{...d,children:e.jsx(rt,{children:e.jsxs(Te,{href:x,target:"_blank",className:"blocklet-interface",underline:"hover",children:[i("common.visit"),e.jsx(lt,{fontSize:"12",sx:{marginLeft:.5}})]})})}):i("blocklet.router.noAccessibleUrl")}const rt=M.div`
  display: flex;
  margin: 4px 0;
`,at=M.div`
  .blocklet-interface {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    white-space: nowrap;

    img {
      margin-right: 4px;
    }
  }
`;Q.propTypes={blocklet:A.object.isRequired,skipAccessibilityCheck:A.bool};function pe({onCancel:j,onSuccess:f}){const{info:d}=me(),{t:i}=X(),{api:S}=Fe(),[r,g]=Ae({loading:!1,title:"",titleError:"",description:"",descriptionError:"",isConnectOpen:!1}),x={title:l=>ce.installBlockletTitleSchema.messages({"*":i("blocklet.titleValidationError")}).validate(l)?.error?.message||"",description:l=>ce.installBlockletDescriptionSchema.messages({"*":i("blocklet.descriptionValidationError")}).validate(l)?.error?.message||""},C=()=>{const l=Re(window?.env?.apiPrefix??"/","/launch-blocklet/install");window.location.href=_e(l,{from:"empty",title:r.title,description:r.description})},v=l=>{g({loading:!1,isConnectOpen:!1}),f(l)},w=()=>{g({loading:!1,isConnectOpen:!1})},B=l=>{const{value:u,name:h}=l.target;g({[`${h}Error`]:u?x[h](u):""})},D=l=>{const{value:u,name:h}=l.target,b=`${h}Error`;r[b]?g({[h]:u,[b]:u?x[h](u):""}):g({[h]:u})};return e.jsxs(e.Fragment,{children:[e.jsx(De,{title:i("blocklet.installFromCreate"),fullWidth:!0,maxWidth:"sm",onClose:()=>j(),showCloseButton:!0,open:!0,actions:e.jsxs(e.Fragment,{children:[e.jsx(K,{onClick:l=>{l.stopPropagation(),j()},color:"inherit",children:i("common.cancel")}),e.jsxs(K,{onClick:l=>{l.stopPropagation(),C()},color:"primary","data-cy":"install-blocklet-next-step",variant:"contained",disabled:r.loading||r.titleError||r.descriptionError||!r.title||!r.description,style:{marginLeft:8},children:[r.loading&&e.jsx(J,{size:16}),i("common.create")]})]}),children:e.jsx(Ee,{component:"div",children:e.jsxs(R,{component:"div",children:[e.jsx(te,{style:{marginBottom:24},label:`Blocklet ${i("common.title")}`,autoComplete:"off",variant:"outlined",fullWidth:!0,autoFocus:!0,name:"title",value:r.title,onBlur:B,onChange:D,error:!!r.titleError,helperText:r.titleError,disabled:r.loading}),e.jsx(te,{label:`Blocklet ${i("common.description")}`,autoComplete:"off",variant:"outlined",fullWidth:!0,name:"description",value:r.description,onBlur:B,onChange:D,error:!!r.descriptionError,helperText:r.descriptionError,disabled:r.loading})]})})}),e.jsx(Ie,{popup:!0,open:r.isConnectOpen,forceConnected:!1,className:"launch-from-create-auth",action:"launch-free-blocklet-by-session",checkFn:S.get,checkTimeout:300*1e3,webWalletUrl:Pe(d),onSuccess:v,extraParams:{title:r.title,description:r.description},messages:{title:i("setup.keyPair.title"),scan:i("setup.keyPair.scan"),confirm:i("setup.keyPair.confirm"),success:i("setup.keyPair.success")},onClose:w})]})}pe.propTypes={onCancel:A.func.isRequired,onSuccess:A.func.isRequired};function fe({onCreate:j=()=>{}}){const f=de(),{t:d}=X(),[i,S]=m.useState(""),[r,g]=m.useState(""),[x,C]=m.useState(null),[v,w]=m.useState(null),B=()=>{C(null)},D=()=>{C({onCancel:()=>{B(),C(null)},onSuccess:()=>{B()}})},l=()=>{w({onCancel:()=>{w(null)},onSuccess:(...b)=>{w(null),j(...b)}})},u=()=>{const b=new URL("http://localhost");b.searchParams.set("restoreFrom","server"),b.searchParams.set("serverUrl",window.location.href),f(`/blocklets/restore${b.search}`)},h=()=>{f("/blocklets/restore")};return e.jsxs(e.Fragment,{children:[e.jsxs(P,{onClick:()=>f("/store"),menuButtonProps:{"data-cy":"open-install-menu"},menu:[e.jsx(P.Item,{"data-cy":"open-install-form",onClick:()=>D(),children:d("blocklet.installFromUrl")},"1"),e.jsx(P.Item,{"data-cy":"open-create-form",onClick:()=>l(),children:d("blocklet.installFromCreate")},"2"),e.jsx(P.Item,{"data-cy":"open-install-from-spaces",onClick:()=>h(),children:d("blocklet.restoreFromSpaces.title")},"3"),e.jsx(P.Item,{"data-cy":"open-install-from-spaces",onClick:()=>u(),children:d("blocklet.installFromDiskBackup")},"4")].filter(Boolean),children:[e.jsx(ot,{}),d("blocklet.installFromMarket")]}),!!i&&e.jsx($,{variant:"error",message:i,onClose:()=>S("")}),!!r&&e.jsx($,{variant:"success",duration:3e3,message:r,onClose:()=>g("")}),x&&e.jsx(tt,{onCancel:x.onCancel,onSuccess:x.onSuccess}),v&&e.jsx(pe,{onCancel:v.onCancel,onSuccess:v.onSuccess})]})}fe.propTypes={onCreate:A.func};function xe({blocklet:j,children:f}){const{urls:d}=ue(j),i=d[0];return f(i||"")}xe.propTypes={blocklet:A.object.isRequired,children:A.func.isRequired};const U="internal",H="external";function Gt(){return e.jsx(Ze,{children:e.jsx(it,{})})}function it(){const j=de(),f=me(),[d,i]=Le(),{data:S,externalData:r,error:g,refresh:x,loading:C}=Ne(),{deletingBlocklets:v,addDeletingDid:w,removeDeletingDid:B,matchDeletingDid:D}=et(),{t:l,locale:u}=X(),h=ze(),b="blocklets-list",_=Je(b),[a,E]=m.useState({searchText:d.get("searchText")||_.searchText||"",pageSize:_.rowsPerPage||10,page:1,sortField:_.sortOrder?.name||"updatedAt",sortDirection:_.sortOrder?.direction||"desc"}),[ge,he]=m.useState(0),be=[{id:U,name:l("blocklet.internal")},{id:H,name:l("blocklet.external")}],[T,ke]=Ke("blocklet-type-filter",U),W=m.useMemo(()=>T===U?S:r,[T,S,r]),[G,je]=m.useState(!1);m.useEffect(()=>{(async()=>{const c={paging:{page:a.page,pageSize:a.pageSize},search:a.searchText,external:T===H,sort:{field:a.sortField,direction:a.sortDirection}},s=await x({silent:G,includeRuntimeInfo:!1,...c});s?.paging&&he(s.paging.total||0),G||je(!0),await x({silent:!0,includeRuntimeInfo:!0,...c})})()},[`${a.page}-${a.pageSize}-${a.searchText}-${a.sortField}-${a.sortDirection}-${T}`]);const ye=m.useCallback(({page:o,rowsPerPage:c,searchText:s,sortOrder:t})=>{a.pageSize!==c?E(n=>({...n,pageSize:c,page:1})):a.page!==o+1?E(n=>({...n,page:o+1})):a.searchText!==s?(E(n=>({...n,searchText:s||"",page:1})),i({searchText:s||""})):t?.name&&t?.direction&&(a.sortField!==t.name||a.sortDirection!==t.direction)&&E(n=>({...n,sortField:t.name,sortDirection:t.direction,page:1}))},[a.pageSize,a.page,a.searchText,a.sortField,a.sortDirection,i]);D(W.map(o=>o.meta.did));const O=m.useCallback(({action:o,blocklet:c})=>{o==="remove"&&w(c.meta.did)},[w]),q=m.useCallback(o=>{if(o.error){$.error(o.error.message),o.action==="remove"&&B(o.blocklet.meta.did);return}o.action==="remove"&&f.refresh({silent:!0})},[f,B]),Y=Ue(o=>o.breakpoints.up("md"));let L=null;const V=m.useMemo(()=>{const o=["installedAt","startedAt","stoppedAt","createdAt"];return(W||[]).map(c=>(o.forEach(s=>{if(c[s]){const t=new Date(c[s]);c[s]=t}}),c))},[W]),k=V,Ce=$e(o=>{if(C)return e.jsx(Me,{relative:"parent",children:e.jsx(J,{})});const{page:c,rowsPerPage:s}=o,t=k.slice(c*s,(c+1)*s);return t.length?e.jsx("div",{children:t.map(n=>e.jsx(xe,{blocklet:n,children:F=>e.jsxs(y,{className:"blocklet-item--mobile",sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(se,{className:"blocklet__avatar",blocklet:n,size:Y?40:60}),e.jsxs(le,{className:"blocklet__content",to:F,onClick:p=>{p.stopPropagation(),F||(p.preventDefault(),$.warning(l("blocklet.router.noAccessibleUrl")))},target:"_blank",children:[e.jsxs(y,{sx:{display:"flex",justifyContent:"space-between",alignItems:"flex-start","& button":{width:24,height:24}},children:[e.jsx(R,{component:"strong",variant:"body1",className:"blocklet__name",children:N.getDisplayName(n,!0)}),e.jsx(ie,{blocklet:n,variant:"menu",onStart:O,onComplete:q},n.meta.did)]}),e.jsxs(R,{component:"small",className:"blocklet__addons",sx:{display:"flex",alignItems:"flex-end"},children:[e.jsx(y,{sx:{display:"flex",alignItems:"center"},children:e.jsx(Q,{blocklet:n,style:{fontSize:14}})}),e.jsx(I,{"status-blocklet-did":n.meta.did,status:n.status,source:n.source,progress:n.progress},n.meta.did)]})]})]})},n.meta.did))}):e.jsx(Ge,{children:l("common.empty")})}),[Se,ve]=m.useState([]),Z=m.useCallback(()=>{const o=Array.from(new Set(k.map(s=>s.status))),c=[{label:l("common.name"),name:"meta.title",options:{filter:!1,sort:!1,customBodyRenderLite(s){const t=k[s];if(!t)return null;const n=N.getAppMissingConfigs(t).length>0?"components":"overview";return e.jsx(le,{to:`/blocklets/${t.meta.did}/${n}`,className:"blocklet-name-wrapper",children:e.jsxs(R,{component:"strong",variant:"body1",className:"blocklet-name",children:[e.jsx(se,{blocklet:t,style:{marginRight:8}}),e.jsxs(y,{children:[e.jsx(y,{children:N.getDisplayName(t)}),e.jsxs(y,{children:[e.jsx(st,{mode:t.mode||""}),!We(t.controller)&&e.jsx(Ye,{type:"primary",children:l("blocklet.external")})]})]})]})},t.meta.did)}}},T===U?{label:l("common.visit"),name:"runtimeInfo.pid",align:"left",options:{sort:!1,filter:!1,customBodyRenderLite(s){const t=k[s];return t?e.jsx(Q,{blocklet:t},t.meta.did):null}}}:null,{label:l("common.uptime"),name:"startedAt",options:{filter:!1,sort:!0,customBodyRenderLite(s){const t=k[s];return t?N.isBlockletRunning(t)&&t.startedAt?e.jsx(z,{value:t.startedAt.getTime(),locale:u},t.meta.did):"":null}}},{label:l("common.installedAt"),name:"installedAt",options:{filter:!1,sort:!0,customBodyRenderLite(s){const t=k[s];return t?t.installedAt?e.jsx(z,{value:t.installedAt.getTime(),locale:u},t.meta.did):t.createdAt?e.jsx(z,{value:t.createdAt.getTime(),locale:u},t.meta.did):"":null}}},{label:l("common.updatedAt"),name:"updatedAt",options:{filter:!1,sort:!0,customBodyRenderLite(s){const t=k[s];return t?e.jsx(z,{value:t.updatedAt,locale:u},t.meta.did):null}}},{label:l("common.status"),name:"status",width:150,align:"center",options:{filter:!0,sort:!0,filterType:"custom",customFilterListOptions:{render:s=>s.map(t=>e.jsx(I,{"data-cy":"blocklet-status-filter-list",status:t},t)),update:(s,t,n)=>(s[n].splice(t,1),s)},filterOptions:{names:o,logic:(s,t)=>t.length?!t.includes(s):!1,display:(s,t,n,F)=>e.jsxs(oe,{children:[e.jsx(qe,{htmlFor:"select-multiple-chip",sx:{background:h.palette.background.default},children:l("common.status")}),e.jsx(ne,{multiple:!0,value:s[n],renderValue:p=>p.map(ee=>e.jsx(I,{"data-cy":"blocklet-status-filter-display",status:ee},ee)),onChange:p=>{s[n]=p.target.value,t(s[n],n,F)},sx:{minWidth:120},children:o.map(p=>e.jsxs(re,{value:p,children:[e.jsx(Ve,{color:"primary",checked:s[n].indexOf(p)>-1}),e.jsx(I,{"data-cy":"blocklet-status-filter",status:p})]},p))})]}),fullWidth:!0},customBodyRenderLite(s){const t=k[s];if(!t)return null;const n=["error","waiting","starting"],F=t.children.filter(p=>n.includes(p.status)||n.includes(p.greenStatus));return e.jsxs(y,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(I,{"data-cy":"blocklet-status","status-blocklet-did":t.meta.did,status:v.includes(t.meta.did)?"deleting":t.status,source:t.source,progress:t.progress},t.meta.did),F.length>0&&e.jsx(Oe,{title:l("blocklet.status.hasSomeErrors",{blocklets:F.map(p=>p.meta.title).join(", ")}),children:e.jsx(y,{sx:{display:"flex",color:"warning.main",ml:1},children:e.jsx(Qe,{})})})]})}}},{label:l("common.actions"),name:"",width:90,options:{sort:!1,filter:!1,customBodyRenderLite(s){const t=k[s];return t?e.jsx(ie,{blocklet:t,variant:"menu",onStart:O,onComplete:q},t.meta.did):null}}}].filter(Boolean);ve(c)},[v,u,q,O,k,l,T,h]);if(m.useEffect(()=>{Z()},[Z]),m.useEffect(()=>{const o=d.get("searchText");o&&o!==a.searchText&&E(c=>({...c,searchText:o,page:1}))},[d]),g)L=e.jsx(ae,{severity:"error",children:e.jsxs("div",{children:[He(g),e.jsx(K,{onClick:()=>x({silent:!1}),children:e.jsx("span",{style:{color:"#44cdc6",textDecoration:"underline"},children:l("common.retry")})})]})});else if(V.length>0||C||a.searchText){const o={};Y||(o.TableBody=Ce),L=e.jsx(ct,{children:e.jsx(Xe,{loading:C,className:"blocklet-list",title:e.jsx(y,{sx:{display:"flex",alignItems:"center"},children:l("blocklet.index.tableTitle")}),locale:u,data:k,columns:Se,durable:b,options:{download:!1,print:!1,searchPlaceholder:l("common.search"),searchAlwaysOpen:!1,sortOrder:{name:a.sortField,direction:a.sortDirection},filterType:"checkbox",page:a.page-1,rowsPerPage:a.pageSize,rowsPerPageOptions:[10,25,50,100],count:ge,searchDebounceTime:600,searchText:a.searchText},onChange:ye,components:o})})}else V.length===0&&(L=e.jsx(ae,{severity:"warning",children:l("blocklet.index.noBlocklet")}));const we=r&&r.length>0;return e.jsxs(mt,{children:[e.jsxs(R,{component:"h2",variant:"h4",className:"page-header",color:"textPrimary",children:[e.jsxs(y,{sx:{display:"flex",alignItems:"center"},children:[l("common.blocklets"),(we||T===H)&&e.jsx(oe,{sx:{ml:1},children:e.jsx(ne,{value:T,onChange:o=>ke(o.target.value),size:"small",children:be.map(o=>e.jsx(re,{value:o.id,children:l(o.name)},o.id))})})]}),e.jsx(nt,{permission:"mutate_blocklets",children:e.jsx(fe,{onCreate:o=>{j(`/blocklets/${o.appDid}/components`)}})})]}),L]})}const ct=M.div`
  .blocklet-item--mobile {
    padding: 16px 0;
  }
`,mt=M.main`
  .page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .blocklet-list {
    .blocklet-item--mobile {
      .blocklet__avatar {
        margin-right: -60px;
      }
      .blocklet__content {
        padding-left: 68px;
        flex: 1;
        display: flex;
        flex-direction: column;
        z-index: 1;
      }
      .blocklet__name {
        font-weight: bold;
        text-decoration: none;
        white-space: normal;
        word-break: break-all;
      }
      .blocklet__addons {
        display: flex;
        justify-content: space-between;
        margin-top: 8px;
      }
    }
    .blocklet-name-wrapper {
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: flex-start;
    }
    .blocklet-name {
      font-weight: bold;
      text-decoration: underline;
      display: flex;
      align-items: center;
      white-space: normal;
      word-break: break-all;
    }

    .blocklet-interface {
      display: flex;
      align-items: center;
      justify-content: flex-start;

      img {
        margin-right: 4px;
      }
    }

    .MuiToolbar-root {
      display: flex;
    }
  }
`;export{it as BlockletList,Gt as default};
