import{Q as U,W as A,bk as H,bD as F,bW as Z,aP as G,b9 as K}from"./vendor-ux-Dl3wVbv_.js";import{W as V,c as _}from"./index-Ca33rdd_.js";import{j as e,G as I,al as g,aY as Q,T as $,an as N,b6 as X,I as D,cf as Y,dP as q,L as J,a7 as ee,z as te,y as oe,bN as ne,M as se,bO as re,aT as ae}from"./vendor-mui-core-D7t4vMS5.js";import{r as i,L as ie}from"./vendor-react-DX7tU9aY.js";import{p as le}from"./util-DCHBQZpP.js";import{u as ce}from"./useLocalStorage-D6axLnAi.js";import{M as T}from"./index-DvQIPWQ6.js";import{d as de,e as M}from"./vendor-utils-BzQg432x.js";import{S as W}from"./shorten-label-1iJcvGQT.js";import{r as O}from"./index-CbZQvtgh.js";import{b as pe}from"./team-7-48iuwj.js";import"./vendor-hooks-DAZ1H6Va.js";import"./vendor-arcblock-ivFYo5vP.js";import"./base32-Cpvj2sD4.js";import"./session-lE2gmzzF.js";import"./purify.es-HRjpPm7y.js";import"./wallet-hidden-topbar-DKISAPb3.js";import"./theme-mode-toggle-BltDSXhy.js";import"./use-mobile-DgmmfWdl.js";import"./index-sb6EjUcD.js";import"./isURL-CpQHQuaa.js";import"./isIP-BBY240SU.js";import"./use-blocklet-logo-BWPJOOVd.js";import"./use-app-logo-BzsLZwwK.js";const B=i.createContext({}),{Provider:ue,Consumer:Ze}=B;function me(){return localStorage.getItem("audit-log-page-size")&&Number(localStorage.getItem("audit-log-page-size"))||10}function fe({children:t,scope:c="",categories:n=[],showScope:l,scopeFormatter:u,blocklets:x}){const{api:h,info:v}=V(),[C,m]=i.useState([]),[f,y]=i.useState({total:0,pageSize:me(),pageCount:0,page:1}),[L,s]=i.useState(!1),[w,a]=i.useState(""),[d,o]=ce(`audit-log-category-${c}`,"all"),S=[{value:"all",label:"All",description:""},{value:"blocklet",label:"Blocklet Management",description:""},{value:"server",label:"Server Management",description:""},{value:"team",label:"Team Management",description:""},{value:"security",label:"Security",description:""},{value:"certificates",label:"Certificate Management",description:""},{value:"integrations",label:"Integration Management",description:""},{value:"gateway",label:"Gateway",description:""}].filter(P=>n.length?P.value==="all"||n.includes(P.value):!0),b=async({page:P=1,pageSize:r=20,silent:z=!0}={})=>{if(!L){z||s(!0);try{const j=await h.getAuditLogs({input:{paging:{page:P,pageSize:r},category:d==="all"?"":d,scope:c,actionOrContent:w}});l&&(j.list||[]).forEach(E=>{E.scope!==v.did&&(E.link=`/blocklets/${E.scope}/components`)}),m(j.list),y(j.paging),s(!1)}catch(j){U.error(j.message),s(!1)}}};i.useEffect(()=>{localStorage.setItem("audit-log-page-size",f.pageSize)},[f.pageSize]),i.useEffect(()=>{b({page:1,pageSize:f.pageSize,silent:!1})},[]),i.useEffect(()=>{b({page:1,pageSize:f.pageSize,silent:!1})},[d,w]);const k={loading:L,fetch:b,filter:{category:d,scope:c},categories:S,blocklets:x,setCategory:o,data:C,paging:f,setPaging:y,showScope:l,scopeFormatter:u,actionOrContent:w,setActionOrContent:a};return e.jsx(ue,{value:{auditLogs:k},children:t})}function R(){const{auditLogs:t}=i.useContext(B);return t}function ge(t){if(!t)return[];const c=/\[([^\]]+)\]\(([^)]+)\)/g,n=[];let l;for(;(l=c.exec(t))!==null;)n.push({text:l[1],url:l[2]});return n}const xe=`
<svg style="width:38px;height:38px;" viewBox="0 0 64 64" fill="none" xmlns="http://www.w3.org/2000/svg">
  <path fill-rule="evenodd" clip-rule="evenodd" d="M50.152 10.6417L31.72 0L13.288 10.6417V24.7942L1 31.8887V53.1722L19.432 63.8139L31.6902 56.7366L31.72 56.7538L31.7498 56.7366L44.008 63.8139L62.44 53.1722V31.8887L50.152 24.7942V10.6417ZM60.52 32.9972L48.232 25.9027V11.7502L31.72 2.21703L15.208 11.7502V25.9028L2.92 32.9972V52.0636L19.432 61.5968L31.6902 54.5196L31.72 54.5368L31.7498 54.5196L44.008 61.5968L60.52 52.0636V32.9972Z" fill="url(#paint0_linear_606_96)"/>
  <path fill-rule="evenodd" clip-rule="evenodd" d="M50.1521 24.8307L31.7201 14.189L13.2881 24.8307V46.1141L31.7201 56.7558L50.1521 46.1141V24.8307ZM15.2081 25.9392L31.7201 16.406L48.2321 25.9392V45.0056L31.7201 54.5388L15.2081 45.0056V25.9392ZM28.5464 23.0464C28.6641 22.6342 29.0408 22.3501 29.4695 22.3501H33.9707C34.3993 22.3501 34.776 22.6342 34.8938 23.0464L35.7504 26.0447L37.8696 27.2681L40.8945 26.5109C41.3103 26.4068 41.7447 26.591 41.959 26.9622L44.2096 30.8604C44.424 31.2316 44.3662 31.6998 44.0682 32.0079L41.8999 34.2489V36.6959L44.0682 38.9369C44.3662 39.245 44.424 39.7133 44.2096 40.0845L41.959 43.9827C41.7447 44.3539 41.3103 44.538 40.8945 44.4339L37.8696 43.6767L35.7504 44.9002L34.8938 47.8984C34.776 48.3106 34.3993 48.5947 33.9707 48.5947H29.4695C29.0408 48.5947 28.6641 48.3106 28.5464 47.8984L27.6897 44.9002L25.5706 43.6767L22.5457 44.4339C22.1299 44.538 21.6955 44.3539 21.4812 43.9827L19.2305 40.0845C19.0162 39.7133 19.0739 39.245 19.372 38.9369L21.5402 36.6959V34.2489L19.372 32.0079C19.0739 31.6998 19.0162 31.2316 19.2305 30.8604L21.4812 26.9622C21.6955 26.591 22.1299 26.4068 22.5457 26.5109L25.5706 27.2681L27.6897 26.0447L28.5464 23.0464ZM28.9861 27.5132C29.2018 27.3887 29.3607 27.1851 29.4292 26.9456L30.1936 24.2701H33.2466L34.011 26.9456C34.0794 27.1851 34.2383 27.3887 34.4541 27.5132L37.2459 29.1251C37.4617 29.2497 37.7174 29.2855 37.9591 29.225L40.6583 28.5493L42.1848 31.1932L40.25 33.193C40.0768 33.372 39.9799 33.6114 39.9799 33.8605V37.0843C39.9799 37.3334 40.0768 37.5728 40.25 37.7518L42.1848 39.7516L40.6583 42.3955L37.9591 41.7198C37.7174 41.6593 37.4617 41.6951 37.2459 41.8197L34.4541 43.4316C34.2383 43.5561 34.0794 43.7597 34.011 43.9992L33.2466 46.6747H30.1936L29.4292 43.9992C29.3607 43.7597 29.2018 43.5561 28.9861 43.4316L26.1942 41.8197C25.9785 41.6951 25.7228 41.6593 25.4811 41.7198L22.7819 42.3955L21.2554 39.7516L23.1902 37.7518C23.3634 37.5728 23.4602 37.3334 23.4602 37.0843V33.8605C23.4602 33.6114 23.3634 33.372 23.1902 33.193L21.2554 31.1932L22.7819 28.5493L25.4811 29.225C25.7228 29.2855 25.9785 29.2497 26.1942 29.1251L28.9861 27.5132ZM31.7201 41.6407C28.3134 41.6407 25.5517 38.8791 25.5517 35.4724C25.5517 32.0657 28.3134 29.3041 31.7201 29.3041C35.1268 29.3041 37.8884 32.0657 37.8884 35.4724C37.8884 38.8791 35.1268 41.6407 31.7201 41.6407ZM35.9684 35.4724C35.9684 37.8187 34.0664 39.7207 31.7201 39.7207C29.3738 39.7207 27.4717 37.8187 27.4717 35.4724C27.4717 33.1261 29.3738 31.2241 31.7201 31.2241C34.0664 31.2241 35.9684 33.1261 35.9684 35.4724Z" fill="url(#paint1_linear_606_96)"/>
  <defs>
  <linearGradient id="paint0_linear_606_96" x1="31.72" y1="95.7208" x2="95.488" y2="34.3249" gradientUnits="userSpaceOnUse">
  <stop stop-color="#0FA4B7"/>
  <stop offset="0.494757" stop-color="#1DC1C7"/>
  <stop offset="1" stop-color="#2BE0D7"/>
  </linearGradient>
  <linearGradient id="paint1_linear_606_96" x1="28.4374" y1="99.2464" x2="98.7613" y2="44.9372" gradientUnits="userSpaceOnUse">
  <stop stop-color="#0FA4B7"/>
  <stop offset="0.494757" stop-color="#1DC1C7"/>
  <stop offset="1" stop-color="#2BE0D7"/>
  </linearGradient>
  </defs>
</svg>
`;function he({title:t,subTitle:c,titleInfo:n,action:l,createdAt:u,content:x,isLast:h,titleLink:v,avatarUrl:C,inService:m,renderTag:f}){const{locale:y}=A(),{palette:L}=I(),[s,w]=i.useState(!1),[a,d]=i.useState(!1),[o,p]=i.useState(window.innerWidth),S=i.useRef(null),b=()=>{const r=S.current?.mdp?.current;r&&d(r.scrollHeight>r.offsetHeight)};i.useEffect(()=>{const r=de(()=>{p(window.innerWidth)},100);return window.addEventListener("resize",r),()=>window.removeEventListener("resize",r)},[]),i.useEffect(()=>{b()},[o,x]);const k=i.useMemo(()=>Object.entries(n).map(([r,z])=>({key:r,value:z})).filter(r=>!!r.value),[n]),P=i.useMemo(()=>{let r=x;return m&&ge(x).forEach(j=>{/^(?:\/[^/]+)*\/blocklets\/[^/]+\/members$/.test(j.url)&&(r=r.replace(j.url,`${_.WELLKNOWN_SERVICE_PATH_PREFIX}/admin/did-connect/members`))}),r},[x,m]);return e.jsx(g,{"data-cy":"log-entry",sx:{borderBottom:h?"none":`1px solid ${L.divider}`,padding:2},children:e.jsxs(g,{sx:{display:"flex",flexDirection:"row",flexWrap:"wrap",gap:2,width:"100%"},children:[e.jsx(g,{sx:{mt:.5},className:"log-author",children:C?e.jsx(Q,{src:C,size:36,shape:"circle"}):e.jsx("div",{dangerouslySetInnerHTML:{__html:xe}})}),e.jsxs(g,{sx:{width:240},children:[e.jsxs(g,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx($,{color:"textSecondary",component:"p",sx:{display:"flex"},children:v?e.jsx(ie,{to:v,target:"_blank",children:e.jsx(W,{maxLength:26,children:t})}):e.jsx(W,{maxLength:26,children:t})}),typeof f=="function"&&f()]}),e.jsx(N,{"aria-label":"Audit device info",title:e.jsx(g,{sx:{color:"#fff",display:"flex",flexDirection:"column",fontSize:12},children:k?.map(r=>e.jsx($,{sx:{fontSize:12,color:"#fff"},children:`${r.key}: ${r.value}`},r.key))}),children:e.jsxs($,{component:"span",color:"textSecondary",sx:{fontSize:13},children:[c,e.jsx(X,{sx:{ml:.5,fontSize:12,verticalAlign:"middle"}})]})})]}),e.jsxs(g,{sx:{width:200},children:[e.jsx($,{sx:{fontSize:"16px",color:L.text.primary,backgroundColor:L.background.default,fontFamily:"-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'"},children:l}),e.jsx($,{component:"span",color:"textSecondary",children:e.jsx(H,{value:u,locale:y,type:"all",disableTimezone:!0,sx:{fontSize:12}})})]}),e.jsx(g,{sx:{flex:1,".wmde-markdown":{bgcolor:"background.default",color:"text.primary",".code-highlight":{"white-space":"pre-wrap;","word-break":"break-all"}}},children:a&&s?e.jsx($,{className:"log-content",color:"textPrimary",component:"div","data-color-mode":"light",gutterBottom:!0,sx:{maxWidth:"lg"},children:e.jsx(T,{source:P,rehypePlugins:[[O,{target:"_blank"}]]})}):e.jsx($,{className:"log-content",color:"textPrimary",component:"div","data-color-mode":"light",gutterBottom:!0,sx:{maxWidth:"lg",display:s?"block":"-webkit-box",WebkitLineClamp:s?"none":2,WebkitBoxOrient:"vertical",overflow:s?"visible":"hidden",wordBreak:"break-word"},children:e.jsx(T,{ref:S,source:P,rehypePlugins:[[O,{target:"_blank"}]]})})}),e.jsxs(g,{children:[a&&e.jsx(D,{size:"small",onClick:()=>w(!s),children:s?e.jsx(Y,{sx:{fontSize:22}}):e.jsx(q,{sx:{fontSize:22}})}),e.jsx(D,{size:"small",children:e.jsx(F,{sx:{fontSize:22},content:x})})]})]})})}const Le=({log:t,info:c,inService:n})=>n?`${_.WELLKNOWN_BLOCKLET_ADMIN_PATH}/members?did=${t.actor.did}`:t.scope===c.did?`/team/members?did=${t.actor.did}`:`/blocklets/${t.scope}/members?did=${t.actor.did}`;function be({log:t,isLast:c}){const{inService:n,info:l}=V(),{t:u}=A(),{teamDid:x}=pe(),{showScope:h,scopeFormatter:v=a=>a,blocklets:C}=R(),m=i.useMemo(()=>{const a=t?.componentDid,d=t?.scope;if(!a)return null;if(n)return(window.blocklet?.componentMountPoints??[]).find(({did:k})=>k===a)||null;const o=C.find(({appPid:b,appDid:k})=>[b,k].includes(d));return o&&(o.children??[]).find(({meta:b})=>b?.did===a)?.meta||null},[C,n,t?.componentDid,t?.scope]);if(!t.actor.did)return null;const f=!["blocklet",""].includes(t.actor.role),y=()=>{if(m){const o=m.title??m.name??"",p=h?` - ${v(t.scope)}`:"";return`${o}${p}`}const a=t.actor.fullName??"",d=h?v(t.scope):"";return a?h?`${a} - ${d}`:a:d},L=h?t.link:Le({log:t,inService:n,info:l}),s=()=>{if(m)return`${n?`${_.WELLKNOWN_SERVICE_PATH_PREFIX}/blocklet/logo-bundle/${t.componentDid}`:`/blocklet/logo-bundle/${t.scope}/${t.componentDid}`}?v=${m?.version}`;const{avatar:a,source:d}=t.actor||{};return a?le(a,x,n,d==="server"):""},w=()=>m?e.jsx(N,{title:t.componentDid,children:e.jsx(K,{type:"success",children:"SDK"},"source")}):"";return e.jsx(he,{isLast:c,isUser:f,avatarDid:t.actor.did,avatarUrl:s(),title:y()||u("common.unrecordedUser"),renderTag:w,titleLink:L,subTitle:t.actor.role?t.actor.role:"guest",content:t.content,action:t.action,inService:n,titleInfo:{IP:t.ip,OS:`${M(t,"env.os.name","")}${M(t,"env.os.version","")}`,Client:`${M(t,"env.browser.name","")}${M(t,"env.browser.Version","")}`},createdAt:t.createdAt})}function ve(){const{t}=A(),{palette:c}=I(),{data:n,loading:l,paging:u,setPaging:x,filter:h,categories:v,setCategory:C,fetch:m,actionOrContent:f,setActionOrContent:y}=R(),L=I(),s=J(L.breakpoints.down("sm")),w=i.useMemo(()=>({flexDirection:s?"column":"row",alignItems:s?"flex-start":"center",justifyContent:s?"flex-start":"space-between","& > div":s?{width:"100%",flex:1,".toolbar-search-area":{width:"100% !important",flex:"1 !important"}}:{}}),[s]),a=o=>{const p=Number(o.target.value);x({...u,pageSize:p}),m({page:1,pageSize:p,silent:!1})},d=o=>{x({...u,page:o+1}),m({page:o+1,pageSize:u.pageSize,silent:!1})};return l&&n.length===0?e.jsx("div",{style:{textAlign:"center",marginTop:"50px"},children:e.jsx(ee,{})}):e.jsxs(Ce,{"data-cy":"audit-logs",children:[e.jsxs(g,{className:"audit-logs-toolbar",sx:{display:"flex",flexDirection:s?"column":"row",gap:2,alignItems:s?"flex-start":"center",justifyContent:s?"flex-start":"space-between",...w},children:[e.jsxs(te,{sx:s?{width:"100%",flex:1}:{width:240,flexShrink:0},variant:"outlined",children:[e.jsx(oe,{children:t("common.filter")}),e.jsx(ne,{size:"small","data-cy":"filter-by-category-trigger",value:h.category,onChange:o=>C(o.target.value),fullWidth:!0,sx:{borderRadius:1},label:t("common.category"),disabled:l,children:v.map(o=>e.jsx(se,{value:o.value,"data-cy":`filter-by-category-${o.value}`,children:e.jsx(g,{children:e.jsx("span",{children:o.label})})},o.label))})]}),e.jsx(Z,{options:{searchPlaceholder:t("common.auditLogsSearch"),searchDebounceTime:600},search:f,searchText:f,searchTextUpdate:y,searchClose:()=>y(""),onSearchOpen:()=>{}})]}),n.length===0&&e.jsx(G,{children:t("common.empty")}),e.jsx(g,{sx:{mt:2,border:n?.length>0?`1px solid ${c.divider}`:"none",borderRadius:1},children:n.length>0&&n.map((o,p)=>e.jsx(be,{log:o,isLast:p===n.length-1},o.id))}),e.jsx(g,{sx:{display:"flex",justifyContent:"flex-end",mt:2},children:e.jsx(re,{disabled:l,page:u.page-1,count:u.total,rowsPerPage:u.pageSize,rowsPerPageOptions:[10,20,50,100],labelRowsPerPage:t("pagination.rowsPerPage"),labelDisplayedRows:({from:o,to:p,count:S})=>`${o}–${p} / ${S!==-1?S:`${t()}more than ${p}`}`,onPageChange:(o,p)=>d(p),onRowsPerPageChange:a})})]})}function Ge({scope:t,categories:c,showScope:n,scopeFormatter:l,blocklets:u}){return e.jsx(fe,{scope:t,categories:c,showScope:n,scopeFormatter:l,blocklets:u,children:e.jsx(ve,{})})}const Ce=ae.div`
  .log-content {
    p {
      margin-bottom: 4px;
    }
    ul,
    ol {
      padding-left: 2rem;
    }
    li {
      list-style-type: disc;
    }
    code.code-highlight {
      max-height: 300px;
      overflow: auto;
    }
  }
`;export{Ge as default};
