import{y as Z}from"./index-BlSr9ZCo.js";import{aS as B,r as d,j as t,H as F,V as D,ab as _,d1 as G,W as V,B as b,cC as K,J as $,bK as X,ad as R,d2 as q,cw as J,av as O,d3 as Q,d4 as Y,al as ee,C as te,F as ne,aC as se,S as oe,M as re,d5 as ie,q as ae,w as E,d6 as le,bN as ce,d7 as de}from"./index-DR3HTfO6.js";import{M as pe}from"./TableSearch-BCTie1Ve.js";import{u as ue}from"./useLocalStorage-BUDMB9ci.js";import{c as fe,v as ge,p as me,s as I,N}from"./index-Dtt8YM5K.js";import{U as xe}from"./UnfoldMore-B_Qg5kjV.js";import{S as T}from"./shorten-label-COgnJGBv.js";import{a as he}from"./team-C7VSpcJN.js";import"./Search-DY52i3Q9.js";import"./Clear-DKF2FhrE.js";import"./blocklet-DX83Lnjp.js";import"./url-evaluation-BsOpcqpZ.js";const U=d.createContext({}),{Provider:Le,Consumer:Fe}=U;function be(){return localStorage.getItem("audit-log-page-size")&&Number(localStorage.getItem("audit-log-page-size"))||10}function ye({children:e,scope:r="",categories:n=[],showScope:p,scopeFormatter:u,blocklets:o}){const{api:y,info:v}=B(),[x,c]=d.useState([]),[f,h]=d.useState({total:0,pageSize:be(),pageCount:0,page:1}),[L,i]=d.useState(!1),[C,a]=d.useState(""),[g,s]=ue(`audit-log-category-${r}`,"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(z=>n.length?z.value==="all"||n.includes(z.value):!0),w=async({page:z=1,pageSize:l=20,silent:P=!0}={})=>{if(!L){P||i(!0);try{const j=await y.getAuditLogs({input:{paging:{page:z,pageSize:l},category:g==="all"?"":g,scope:r,actionOrContent:C}});p&&(j.list||[]).forEach(M=>{M.scope!==v.did&&(M.link=`/blocklets/${M.scope}/components`)}),c(j.list),h(j.paging),i(!1)}catch(j){F.error(j.message),i(!1)}}};d.useEffect(()=>{localStorage.setItem("audit-log-page-size",f.pageSize)},[f.pageSize]),d.useEffect(()=>{w({page:1,pageSize:f.pageSize,silent:!1})},[]),d.useEffect(()=>{w({page:1,pageSize:f.pageSize,silent:!1})},[g,C]);const k={loading:L,fetch:w,filter:{category:g,scope:r},categories:S,blocklets:o,setCategory:s,data:x,paging:f,setPaging:h,showScope:p,scopeFormatter:u,actionOrContent:C,setActionOrContent:a};return t.jsx(Le,{value:{auditLogs:k},children:e})}function H(){const{auditLogs:e}=d.useContext(U);return e}const Ce=/^[a-zA-Z][a-zA-Z\d+\-.]*?:/,ve=/^[a-zA-Z]:\\/;function we(e){if(typeof e!="string")throw new TypeError(`Expected a \`string\`, got \`${typeof e}\``);return ve.test(e)?!1:Ce.test(e)}const Se=["http","https"],je=["nofollow"],ke={};function W(e){const r=e||ke,n=r.protocols||Se,p=fe(r.test);return function(u){ge(u,"element",function(o,y,v){if(o.tagName==="a"&&typeof o.properties.href=="string"&&p(o,y,v)){const x=o.properties.href;if(we(x)?n.includes(x.slice(0,x.indexOf(":"))):x.startsWith("//")){const c=A(r.content,o),f=c&&!Array.isArray(c)?[c]:c,h=A(r.rel,o)||je,L=typeof h=="string"?me(h):h,i=A(r.target,o),C=A(r.properties,o);if(C&&Object.assign(o.properties,I(C)),L.length>0&&(o.properties.rel=[...L]),i&&(o.properties.target=i),f){const a=A(r.contentProperties,o)||{};o.children.push({type:"element",tagName:"span",properties:I(a),children:I(f)})}}}})}}function A(e,r){return typeof e=="function"?e(r):e}function ze(e){if(!e)return[];const r=/\[([^\]]+)\]\(([^)]+)\)/g,n=[];let p;for(;(p=r.exec(e))!==null;)n.push({text:p[1],url:p[2]});return n}const $e=`
<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 Ae({title:e,subTitle:r,titleInfo:n,action:p,createdAt:u,content:o,isLast:y,titleLink:v,avatarUrl:x,inService:c,renderTag:f}){const{locale:h}=D(),{palette:L}=_(),[i,C]=d.useState(!1),[a,g]=d.useState(!1),[s,m]=d.useState(window.innerWidth),S=d.useRef(null),w=()=>{const l=S.current?.mdp?.current;l&&g(l.scrollHeight>l.offsetHeight)};d.useEffect(()=>{const l=G(()=>{m(window.innerWidth)},100);return window.addEventListener("resize",l),()=>window.removeEventListener("resize",l)},[]),d.useEffect(()=>{w()},[s,o]);const k=d.useMemo(()=>Object.entries(n).map(([l,P])=>({key:l,value:P})).filter(l=>!!l.value),[n]),z=d.useMemo(()=>{let l=o;return c&&ze(o).forEach(j=>{/^(?:\/[^/]+)*\/blocklets\/[^/]+\/members$/.test(j.url)&&(l=l.replace(j.url,`${V}/admin/did-connect/members`))}),l},[o,c]);return t.jsx(b,{"data-cy":"log-entry",sx:{borderBottom:y?"none":`1px solid ${L.divider}`,padding:2},children:t.jsxs(b,{sx:{display:"flex",flexDirection:"row",flexWrap:"wrap",gap:2,width:"100%"},children:[t.jsx(b,{sx:{mt:.5},className:"log-author",children:x?t.jsx(K,{src:x,size:36,shape:"circle"}):t.jsx("div",{dangerouslySetInnerHTML:{__html:$e}})}),t.jsxs(b,{sx:{width:240},children:[t.jsxs(b,{sx:{display:"flex",alignItems:"center",gap:.5},children:[t.jsx($,{color:"textSecondary",component:"p",sx:{display:"flex"},children:v?t.jsx(X,{to:v,target:"_blank",children:t.jsx(T,{maxLength:26,children:e})}):t.jsx(T,{maxLength:26,children:e})}),typeof f=="function"&&f()]}),t.jsx(R,{"aria-label":"Audit device info",title:t.jsx(b,{sx:{color:"#fff",display:"flex",flexDirection:"column",fontSize:12},children:k?.map(l=>t.jsx($,{sx:{fontSize:12,color:"#fff"},children:`${l.key}: ${l.value}`},l.key))}),children:t.jsxs($,{component:"span",color:"textSecondary",sx:{fontSize:13},children:[r,t.jsx(q,{sx:{ml:.5,fontSize:12,verticalAlign:"middle"}})]})})]}),t.jsxs(b,{sx:{width:200},children:[t.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:p}),t.jsx($,{component:"span",color:"textSecondary",children:t.jsx(J,{value:u,locale:h,type:"all",disableTimezone:!0,sx:{fontSize:12}})})]}),t.jsx(b,{sx:{flex:1,".wmde-markdown":{bgcolor:"background.default",color:"text.primary",".code-highlight":{"white-space":"pre-wrap;","word-break":"break-all"}}},children:a&&i?t.jsx($,{className:"log-content",color:"textPrimary",component:"div","data-color-mode":"light",gutterBottom:!0,sx:{maxWidth:"lg"},children:t.jsx(N,{source:z,rehypePlugins:[[W,{target:"_blank"}]]})}):t.jsx($,{className:"log-content",color:"textPrimary",component:"div","data-color-mode":"light",gutterBottom:!0,sx:{maxWidth:"lg",display:i?"block":"-webkit-box",WebkitLineClamp:i?"none":2,WebkitBoxOrient:"vertical",overflow:i?"visible":"hidden",wordBreak:"break-word"},children:t.jsx(N,{ref:S,source:z,rehypePlugins:[[W,{target:"_blank"}]]})})}),t.jsxs(b,{children:[a&&t.jsx(O,{size:"small",onClick:()=>C(!i),children:i?t.jsx(Q,{sx:{fontSize:22}}):t.jsx(xe,{sx:{fontSize:22}})}),t.jsx(O,{size:"small",children:t.jsx(Y,{sx:{fontSize:22},content:o})})]})]})})}const Pe=({log:e,info:r,inService:n})=>n?`${le}/members?did=${e.actor.did}`:e.scope===r.did?`/team/members?did=${e.actor.did}`:`/blocklets/${e.scope}/members?did=${e.actor.did}`;function Ee({log:e,isLast:r}){const{inService:n,info:p}=B(),{t:u}=D(),{teamDid:o}=he(),{showScope:y,scopeFormatter:v=a=>a,blocklets:x}=H(),c=d.useMemo(()=>{const a=e?.componentDid,g=e?.scope;if(!a)return null;if(n)return(window.blocklet?.componentMountPoints??[]).find(({did:k})=>k===a)||null;const s=x.find(({appPid:w,appDid:k})=>[w,k].includes(g));return s&&(s.children??[]).find(({meta:w})=>w?.did===a)?.meta||null},[x,n,e?.componentDid,e?.scope]);if(!e.actor.did)return null;const f=!["blocklet",""].includes(e.actor.role),h=()=>{if(c){const s=c.title??c.name??"",m=y?` - ${v(e.scope)}`:"";return`${s}${m}`}const a=e.actor.fullName??"",g=y?v(e.scope):"";return a?y?`${a} - ${g}`:a:g},L=y?e.link:Pe({log:e,inService:n,info:p}),i=()=>{if(c)return`${n?`${V}/blocklet/logo-bundle/${e.componentDid}`:`/blocklet/logo-bundle/${e.scope}/${e.componentDid}`}?v=${c?.version}`;const{avatar:a,source:g}=e.actor||{};return a?de(a,o,n,g==="server"):""},C=()=>c?t.jsx(R,{title:e.componentDid,children:t.jsx(ce,{type:"success",children:"SDK"},"source")}):"";return t.jsx(Ae,{isLast:r,isUser:f,avatarDid:e.actor.did,avatarUrl:i(),title:h()||u("common.unrecordedUser"),renderTag:C,titleLink:L,subTitle:e.actor.role?e.actor.role:"guest",content:e.content,action:e.action,inService:n,titleInfo:{IP:e.ip,OS:`${E(e,"env.os.name","")}${E(e,"env.os.version","")}`,Client:`${E(e,"env.browser.name","")}${E(e,"env.browser.Version","")}`},createdAt:e.createdAt})}function Me(){const{t:e}=D(),{palette:r}=_(),{data:n,loading:p,paging:u,setPaging:o,filter:y,categories:v,setCategory:x,fetch:c,actionOrContent:f,setActionOrContent:h}=H(),L=_(),i=ee(L.breakpoints.down("sm")),C=d.useMemo(()=>({flexDirection:i?"column":"row",alignItems:i?"flex-start":"center",justifyContent:i?"flex-start":"space-between","& > div":i?{width:"100%",flex:1,".toolbar-search-area":{width:"100% !important",flex:"1 !important"}}:{}}),[i]),a=s=>{const m=Number(s.target.value);o({...u,pageSize:m}),c({page:1,pageSize:m,silent:!1})},g=s=>{o({...u,page:s+1}),c({page:s+1,pageSize:u.pageSize,silent:!1})};return p&&n.length===0?t.jsx("div",{style:{textAlign:"center",marginTop:"50px"},children:t.jsx(te,{})}):t.jsxs(Ie,{"data-cy":"audit-logs",children:[t.jsxs(b,{className:"audit-logs-toolbar",sx:{display:"flex",flexDirection:i?"column":"row",gap:2,alignItems:i?"flex-start":"center",justifyContent:i?"flex-start":"space-between",...C},children:[t.jsxs(ne,{sx:i?{width:"100%",flex:1}:{width:240,flexShrink:0},variant:"outlined",children:[t.jsx(se,{children:e("common.filter")}),t.jsx(oe,{size:"small","data-cy":"filter-by-category-trigger",value:y.category,onChange:s=>x(s.target.value),fullWidth:!0,sx:{borderRadius:1},label:e("common.category"),disabled:p,children:v.map(s=>t.jsx(re,{value:s.value,"data-cy":`filter-by-category-${s.value}`,children:t.jsx(b,{children:t.jsx("span",{children:s.label})})},s.label))})]}),t.jsx(pe,{options:{searchPlaceholder:e("common.auditLogsSearch"),searchDebounceTime:600},search:f,searchText:f,searchTextUpdate:h,searchClose:()=>h(""),onSearchOpen:()=>{}})]}),n.length===0&&t.jsx(Z,{children:e("common.empty")}),t.jsx(b,{sx:{mt:2,border:n?.length>0?`1px solid ${r.divider}`:"none",borderRadius:1},children:n.length>0&&n.map((s,m)=>t.jsx(Ee,{log:s,isLast:m===n.length-1},s.id))}),t.jsx(b,{sx:{display:"flex",justifyContent:"flex-end",mt:2},children:t.jsx(ie,{disabled:p,page:u.page-1,count:u.total,rowsPerPage:u.pageSize,rowsPerPageOptions:[10,20,50,100],labelRowsPerPage:e("pagination.rowsPerPage"),labelDisplayedRows:({from:s,to:m,count:S})=>`${s}–${m} / ${S!==-1?S:`${e()}more than ${m}`}`,onPageChange:(s,m)=>g(m),onRowsPerPageChange:a})})]})}function Ge({scope:e,categories:r,showScope:n,scopeFormatter:p,blocklets:u}){return t.jsx(ye,{scope:e,categories:r,showScope:n,scopeFormatter:p,blocklets:u,children:t.jsx(Me,{})})}const Ie=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};
