import{o as e}from"./rolldown-runtime.C0FnF6B9.js";import{r as t}from"./emotion-is-prop-valid.esm.CuYlOKOk.js";import{a as n,i as r,t as i}from"./emotion-styled.browser.esm.Dj5rZcu_.js";import{f as a}from"./getColors.CymiOtHO.js";import{t as o}from"./DynamicIcon.CshBYn8E.js";import{t as s}from"./useEmotionTheme.cgGerbj0.js";import{t as c}from"./ErrorElement.CZxpg0mG.js";import{r as l,t as u}from"./useFloatingOverlay.DP8o9Tmt.js";import{t as d}from"./useCopyToClipboard.C-ywP4Jl.js";import{X as f,_ as p}from"./index.ByR4Z2EF.js";import{t as m}from"./dist.M42-4E3x.js";import{t as h}from"./reactJsonViewCompat.ZSQC4eoO.js";var g=e(t(),1),_=e(m(),1),v=i(`div`,{target:`epagahn0`})(({theme:e})=>({overflowY:`auto`,position:`relative`,".react-json-view .copy-icon svg":{fontSize:`1em !important`,marginRight:`${e.spacing.threeXS} !important`,verticalAlign:`middle !important`}})),y=i(`div`,{target:`epagahn1`})(({theme:e})=>({display:`flex`,alignItems:`center`,gap:e.spacing.sm,padding:e.spacing.sm,paddingLeft:e.spacing.md,fontFamily:e.genericFonts.codeFont,fontSize:e.fontSizes.twoSm,color:e.colors.bodyText,maxWidth:`90vw`,wordBreak:`break-all`})),b=i(`button`,{target:`epagahn2`})(({theme:e})=>({display:`flex`,alignItems:`center`,justifyContent:`center`,padding:e.spacing.threeXS,backgroundColor:`transparent`,border:`none`,borderRadius:e.radii.sm,cursor:`pointer`,color:e.colors.fadedText60,transition:`color 0.15s ease, background-color 0.15s ease`,"&:hover":{backgroundColor:e.colors.darkenedBgMix15,color:e.colors.bodyText},"&:active":{backgroundColor:e.colors.darkenedBgMix25},"&:focus":{outline:`none`},"&:focus-visible":{boxShadow:e.shadows.focusRing}})),x=i(`div`,{target:`epagahn3`})(({theme:e})=>({backgroundColor:a(e)?e.colors.bgColor:e.colors.secondaryBg,borderRadius:e.radii.default,boxShadow:e.shadows.tooltip,overflow:`hidden`,zIndex:e.zIndices.popup}));function S({top:e,left:t,path:i,clearTooltip:a}){let{isCopied:s,copyToClipboard:c,label:p}=d(),{refs:m,floatingStyles:h}=u({open:!0,placement:`top`,offsetPx:15}),_=(0,g.useRef)(0);(0,g.useEffect)(()=>{_.current=Date.now()},[]);let v=(0,g.useRef)(a);(0,g.useEffect)(()=>{v.current=a},[a]);let S=(0,g.useRef)(null);(0,g.useEffect)(()=>{m.setReference({getBoundingClientRect:()=>({x:t,y:e,top:e,left:t,bottom:e,right:t,width:0,height:0})})},[m,e,t]);let C=(0,g.useCallback)(e=>{m.setFloating(e),S.current=e},[m]);(0,g.useEffect)(()=>{let e=e=>{Date.now()-_.current<50||S.current?.contains(e.target)||v.current()},t=e=>{e.key===`Escape`&&(e.stopPropagation(),v.current())};return document.addEventListener(`click`,e),document.addEventListener(`keydown`,t,!0),()=>{document.removeEventListener(`click`,e),document.removeEventListener(`keydown`,t,!0)}},[]);let w=(0,g.useCallback)(()=>{c(i)},[c,i]);return r(l,{id:f,children:r(x,{ref:C,"data-testid":`stJsonPathTooltipBody`,style:h,role:`dialog`,"aria-label":`JSON path`,children:n(y,{"data-testid":`stJsonPathTooltip`,children:[r(`code`,{children:i}),r(b,{onClick:w,title:p,"aria-label":p,autoFocus:!0,children:r(o,{size:`sm`,iconValue:s?`:material/check:`:`:material/content_copy:`})})]})})})}var C=(0,g.memo)(S);function w(e){return e.length===0?`$`:e.reduce((e,t,n)=>t===null?e:/^\d+$/.test(t)?`${e}[${t}]`:t===``||/[^a-zA-Z0-9_$]/.test(t)||/^\d/.test(t)?`${e}["${t.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}"]`:n===0||e===``?t:`${e}.${t}`,``)}function T(){let[e,t]=(0,g.useState)(null),n=(0,g.useRef)({x:0,y:0});return(0,g.useEffect)(()=>{let e=e=>{n.current={x:e.clientX,y:e.clientY}};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]),{tooltip:e,handleSelect:(0,g.useCallback)(e=>{let{x:r,y:i}=n.current,a=w([...e.namespace,e.name]);t({path:a,x:r,y:i})},[]),clearTooltip:(0,g.useCallback)(()=>{t(null)},[])}}function E({element:e}){let t=s(),{tooltip:i,handleSelect:o,clearTooltip:l}=T(),{copyToClipboard:u}=d(),f=(0,g.useCallback)(e=>{u(JSON.stringify(e.src))},[u]),m;try{m=JSON.parse(e.body)}catch(t){let n=p(t);try{m=_.default.parse(e.body)}catch{let t=parseInt(n.message.replace(/[^0-9]/g,``),10);return n.message+=`\n${e.body.substring(0,t+1)} ← here`,r(c,{name:`Json Parse Error`,message:n.message})}}let y=a(t)?`rjv-default`:`monokai`;return n(v,{className:`stJson`,"data-testid":`stJson`,children:[r(h,{src:m,collapsed:e.maxExpandDepth??!e.expanded,displayDataTypes:!1,displayObjectSize:!1,name:!1,theme:y,enableClipboard:f,onSelect:o,showComma:!1,style:{fontFamily:t.genericFonts.codeFont,fontSize:t.fontSizes.codeFontSize,fontWeight:t.fontWeights.code,backgroundColor:t.colors.bgColor,whiteSpace:`pre-wrap`}}),i&&r(C,{top:i.y,left:i.x,path:i.path,clearTooltip:l})]})}var D=(0,g.memo)(E);export{D as default};