import{r as w,g as C,j as t,F as S,S as L,au as T,M as D,aV as I,B as P,q as B,o as F}from"./index-DR3HTfO6.js";import{u as $}from"./useLocalStorage-BUDMB9ci.js";import{L as k,D as z}from"./download-CJnLFQi9.js";import{L as A}from"./ListSubheader-CD838Q5u.js";import"./ButtonGroup-BjIAZaBg.js";import"./getValidReactChildren-DB5-GZmu.js";const E=B.div`
  display: flex;
  justify-items: flex-start;
  align-items: center;
  gap: 8px;
  .name {
    display: block;
    max-width: 260px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
`;function M({blocklet:a,...i}){const h=['Tip: this tab will only show runtime logs. Please go to "Blocklet Server" to view other lifecycle logs of the blocklet (install/start/stop...)',`\r
\r
`],s=(a?.children||[]).map(e=>({did:e.meta.did,name:e.meta.title,types:["error","info","access","stdout","stderr"],component:e}));s.sort((e,r)=>e.name.localeCompare(r.name));const[l,d]=w.useState(""),[u,x]=C(),c=u.get("component"),[f,m]=$(`blocklet-log-${a.meta.did}`,"");let[o,p]=f.split(",");s.find(e=>e.did===o)||(o=s[0]?.did),c&&(o=c);const g=e=>{x({component:e.target.value}),m([e.target.value,p].join(","))},y=s.filter(e=>e.name.toLowerCase().includes(l.toLowerCase())),v=t.jsx(S,{sx:{minWidth:240,maxWidth:300},children:t.jsxs(L,{MenuProps:{autoFocus:!1},value:o,onChange:g,onClose:()=>d(""),size:"small",variant:"outlined",children:[t.jsx(A,{children:t.jsx(T,{autoFocus:!0,value:l,placeholder:"Search",variant:"outlined",size:"small",fullWidth:!0,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key!=="Escape"&&e.stopPropagation()}})}),y.map(e=>t.jsx(D,{value:e.did,children:t.jsxs(E,{children:[t.jsx(I,{size:24,blocklet:e.component,ancestors:[a]}),t.jsx("span",{className:"name",children:e.name})]})},e.did))]})}),n=s.find(e=>e.did===o)||s[0]||a.meta,j=e=>{const r=n.types.indexOf(e);m([o,r||0].join(","))};return t.jsx(P,{...i,sx:[{height:{xs:"calc(100vh - 444px)",sm:"calc(100vh - 508px)",md:"calc(100vh - 445px)"}},...Array.isArray(i.sx)?i.sx:[i.sx]],children:t.jsx(k,{logId:n===a.meta?`blocklet-${a.meta.did}`:`blocklet-${a.meta.did}/${n.did}`,initialData:h,prepend:v,postpend:t.jsx(z,{id:a.meta.did,name:a.meta.name}),name:n.name,types:n.types,defaultTypeIndex:p,onTypeChange:j},n.did)})}M.propTypes={blocklet:F.object.isRequired};export{M as default};
