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.BYv_Qzcq.js";import{f as a}from"./getColors.DtAxY2Hd.js";import{t as o}from"./DynamicIcon.qdIiJ9dI.js";import{t as s}from"./useEmotionTheme.Dmt_qJ4x.js";import{t as c}from"./ErrorElement.Bn6KKjq6.js";import{r as l,t as u}from"./useFloatingOverlay.Cpeg7fG2.js";import{t as d}from"./useCopyToClipboard.C-ywP4Jl.js";import{t as f}from"./ErrorHandling.H5STbbYb.js";import{t as p}from"./dist.M42-4E3x.js";import{t as m}from"./reactJsonViewCompat.ZSQC4eoO.js";var h=e(t(),1),g=e(p(),1),_=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`}})),v=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`})),y=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}})),b=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 x({top:e,left:t,path:i,clearTooltip:a}){let{isCopied:s,copyToClipboard:c,label:f}=d(),{refs:p,floatingStyles:m}=u({open:!0,placement:`top`,offsetPx:15}),g=(0,h.useRef)(0);(0,h.useEffect)(()=>{g.current=Date.now()},[]);let _=(0,h.useRef)(a);(0,h.useEffect)(()=>{_.current=a},[a]);let x=(0,h.useRef)(null);(0,h.useEffect)(()=>{p.setReference({getBoundingClientRect:()=>({x:t,y:e,top:e,left:t,bottom:e,right:t,width:0,height:0})})},[p,e,t]);let S=(0,h.useCallback)(e=>{p.setFloating(e),x.current=e},[p]);(0,h.useEffect)(()=>{let e=e=>{Date.now()-g.current<50||x.current?.contains(e.target)||_.current()},t=e=>{e.key===`Escape`&&(e.stopPropagation(),_.current())};return document.addEventListener(`click`,e),document.addEventListener(`keydown`,t,!0),()=>{document.removeEventListener(`click`,e),document.removeEventListener(`keydown`,t,!0)}},[]);let C=(0,h.useCallback)(()=>{c(i)},[c,i]);return r(l,{children:r(b,{ref:S,"data-testid":`stJsonPathTooltipBody`,style:m,role:`dialog`,"aria-label":`JSON path`,children:n(v,{"data-testid":`stJsonPathTooltip`,children:[r(`code`,{children:i}),r(y,{onClick:C,title:f,"aria-label":f,autoFocus:!0,children:r(o,{size:`sm`,iconValue:s?`:material/check:`:`:material/content_copy:`})})]})})})}var S=(0,h.memo)(x);function C(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 w(){let[e,t]=(0,h.useState)(null),n=(0,h.useRef)({x:0,y:0});return(0,h.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,h.useCallback)(e=>{let{x:r,y:i}=n.current,a=C([...e.namespace,e.name]);t({path:a,x:r,y:i})},[]),clearTooltip:(0,h.useCallback)(()=>{t(null)},[])}}function T({element:e}){let t=s(),{tooltip:i,handleSelect:o,clearTooltip:l}=w(),{copyToClipboard:u}=d(),p=(0,h.useCallback)(e=>{u(JSON.stringify(e.src))},[u]),v;try{v=JSON.parse(e.body)}catch(t){let n=f(t);try{v=g.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(_,{className:`stJson`,"data-testid":`stJson`,children:[r(m,{src:v,collapsed:e.maxExpandDepth??!e.expanded,displayDataTypes:!1,displayObjectSize:!1,name:!1,theme:y,enableClipboard:p,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(S,{top:i.y,left:i.x,path:i.path,clearTooltip:l})]})}var E=(0,h.memo)(T);export{E as default};