import{z as f,r,l as b,aI as y,j as c,aJ as S,aw as x,o as h,m as T,Y as R,aK as v,aL as B,aM as E}from"./index.Drusyo5m.js";import{l as J}from"./index.8HslT92O.js";import{R as k}from"./main.D_CmqChN.js";const w=f("div",{target:"eem6pay0"})(({theme:o})=>({overflowY:"auto",position:"relative",".react-json-view .copy-icon svg":{fontSize:"1em !important",marginRight:`${o.spacing.threeXS} !important`,verticalAlign:"middle !important"}})),L=f("div",{target:"eem6pay1"})(({theme:o})=>({display:"flex",alignItems:"center",gap:o.spacing.sm,padding:o.spacing.sm,paddingLeft:o.spacing.md,fontFamily:o.genericFonts.codeFont,fontSize:o.fontSizes.twoSm,color:o.colors.bodyText,maxWidth:"90vw",wordBreak:"break-all"})),$=f("button",{target:"eem6pay2"})(({theme:o})=>({display:"flex",alignItems:"center",justifyContent:"center",padding:o.spacing.threeXS,backgroundColor:"transparent",border:"none",borderRadius:o.radii.md,cursor:"pointer",color:o.colors.fadedText60,transition:"color 0.15s ease, background-color 0.15s ease","&:hover":{backgroundColor:o.colors.darkenedBgMix15,color:o.colors.bodyText},"&:active":{backgroundColor:o.colors.darkenedBgMix25},"&:focus":{outline:"none"},"&:focus-visible":{boxShadow:o.shadows.focusRing}})),I=f("div",{target:"eem6pay3"})(({top:o,left:e})=>({position:"fixed",top:o,left:e}));function P({top:o,left:e,path:t,clearTooltip:d}){const[p,n]=r.useState(!0),s=b(),{colors:i,radii:a}=s,{isCopied:l,copyToClipboard:u,label:m}=y(),g=r.useCallback(()=>{n(!1),d()},[d]),C=r.useCallback(()=>{u(t)},[u,t]);return c(v,{content:h(L,{"data-testid":"stJsonPathTooltip",children:[c("code",{children:t}),c($,{onClick:C,title:m,"aria-label":m,autoFocus:!0,children:c(R,{size:"sm",iconValue:l?":material/check:":":material/content_copy:"})})]}),placement:x.top,accessibilityType:S.tooltip,showArrow:!1,popoverMargin:15,onClickOutside:g,onEsc:g,overrides:{Body:{style:{borderTopLeftRadius:a.default,borderTopRightRadius:a.default,borderBottomLeftRadius:a.default,borderBottomRightRadius:a.default,paddingTop:"0 !important",paddingBottom:"0 !important",paddingLeft:"0 !important",paddingRight:"0 !important",backgroundColor:"transparent"}},Inner:{style:{backgroundColor:T(s)?i.bgColor:i.secondaryBg,color:i.bodyText,borderTopLeftRadius:a.default,borderTopRightRadius:a.default,borderBottomLeftRadius:a.default,borderBottomRightRadius:a.default,paddingTop:"0 !important",paddingBottom:"0 !important",paddingLeft:"0 !important",paddingRight:"0 !important"}}},isOpen:p,children:c(I,{"data-testid":"stJsonPathTooltipTarget",top:o,left:e})})}const j=r.memo(P);function z(o){return o.length===0?"$":o.reduce((e,t,d)=>{if(t===null)return e;if(/^\d+$/.test(t))return`${e}[${t}]`;if(t===""||/[^a-zA-Z0-9_$]/.test(t)||/^\d/.test(t)){const s=t.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`${e}["${s}"]`}return d===0||e===""?t:`${e}.${t}`},"")}function F(){const[o,e]=r.useState(null),t=r.useRef({x:0,y:0});r.useEffect(()=>{const n=s=>{t.current={x:s.clientX,y:s.clientY}};return document.addEventListener("mousedown",n),()=>document.removeEventListener("mousedown",n)},[]);const d=r.useCallback(n=>{const{x:s,y:i}=t.current,a=[...n.namespace,n.name],l=z(a);e({path:l,x:s,y:i})},[]),p=r.useCallback(()=>{e(null)},[]);return{tooltip:o,handleSelect:d,clearTooltip:p}}function A({element:o}){const e=b(),{tooltip:t,handleSelect:d,clearTooltip:p}=F(),{copyToClipboard:n}=y(),s=r.useCallback(l=>{n(JSON.stringify(l.src))},[n]);let i;try{i=JSON.parse(o.body)}catch(l){const u=B(l);try{i=J.parse(o.body)}catch{const g=parseInt(u.message.replace(/[^0-9]/g,""),10);return u.message+=`
${o.body.substring(0,g+1)} ← here`,c(E,{name:"Json Parse Error",message:u.message})}}const a=T(e)?"rjv-default":"monokai";return h(w,{className:"stJson","data-testid":"stJson",children:[c(k,{src:i,collapsed:o.maxExpandDepth??!o.expanded,displayDataTypes:!1,displayObjectSize:!1,name:!1,theme:a,enableClipboard:s,onSelect:d,style:{fontFamily:e.genericFonts.codeFont,fontSize:e.fontSizes.codeFontSize,fontWeight:e.fontWeights.code,backgroundColor:e.colors.bgColor,whiteSpace:"pre-wrap"}}),t&&c(j,{top:t.y,left:t.x,path:t.path,clearTooltip:p})]})}const Y=r.memo(A);export{Y as default};
