import{ar as O,aY as x,aT as t,g as J,aq as A,e as j,U as z,u as I}from"./chunk-02oqS8tD.js";import{C as M}from"./chunk-D4UWVV5_.js";/**
 * @license lucide-react v0.451.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const S=O("Braces",[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]]);/**
 * @license lucide-react v0.451.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const E=O("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]),N=50,T=2,w=240;function R({value:e,label:s,collapsedByDefault:r=!0}){const[n,a]=x.useState("tree"),[i,c]=x.useState(""),[m,d]=x.useState(!r),[p,f]=x.useState(null),h=x.useMemo(()=>{try{return JSON.stringify(e,null,2)}catch{return"// This value could not be serialised (it contains a circular reference or an unsupported type)."}},[e]),g=(l,u)=>{navigator.clipboard.writeText(l).then(()=>{f(u),window.setTimeout(()=>f(null),1400)}).catch(()=>f(null))};return m?t.jsxs("div",{className:"rounded-lg border border-stroke/70 dark:border-stroke/25",children:[t.jsxs("div",{className:"flex items-center gap-1 border-b border-stroke/50 px-1.5 py-1 dark:border-stroke/20",children:[t.jsx("div",{className:"flex gap-0.5 rounded bg-stroke/15 p-0.5 dark:bg-white/[0.04]",children:["tree","raw"].map(l=>t.jsxs("button",{type:"button",onClick:()=>a(l),className:A("flex min-h-6 items-center gap-1 rounded px-2 text-[9px] font-semibold capitalize transition-colors",n===l?"bg-white text-dynamic-azure shadow-sm dark:bg-midnight-navy":"text-muted-foreground"),children:[l==="tree"?t.jsx(S,{className:"h-2 w-2"}):t.jsx(E,{className:"h-2 w-2"}),l]},l))}),t.jsxs("button",{type:"button",onClick:()=>g(h,"all"),title:"Copy the whole value",className:"ml-auto flex min-h-6 items-center gap-1 rounded px-2 text-[9px] font-semibold text-muted-foreground hover:bg-stroke/20 hover:text-foreground",children:[p==="all"?t.jsx(j,{className:"h-2 w-2 text-emerald-600"}):t.jsx(M,{className:"h-2 w-2"}),p==="all"?"Copied":"Copy"]}),t.jsx("button",{type:"button",onClick:()=>d(!1),className:"min-h-6 rounded px-2 text-[9px] font-semibold text-muted-foreground hover:bg-stroke/20 hover:text-foreground",children:"Hide"})]}),n==="tree"&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"border-b border-stroke/50 px-1.5 py-1 dark:border-stroke/20",children:t.jsxs("div",{className:"relative",children:[t.jsx(z,{className:"absolute left-1.5 top-1/2 h-2.5 w-2.5 -translate-y-1/2 text-muted-foreground"}),t.jsx(I,{value:i,onChange:l=>c(l.target.value),placeholder:"Filter keys and values",className:"h-6 pl-6 text-[10px]"})]})}),t.jsx("div",{className:"max-h-[320px] overflow-auto p-1.5",children:t.jsx(L,{value:e,path:"",name:"",depth:0,query:i.trim().toLowerCase(),onCopy:g,copied:p})})]}),n==="raw"&&t.jsx("pre",{className:"max-h-[320px] overflow-auto p-2 font-mono text-[9.5px] leading-snug",children:h})]}):t.jsxs("button",{type:"button",onClick:()=>d(!0),className:"flex w-full items-center gap-1.5 rounded-lg border border-stroke/70 px-2 py-1.5 text-left transition-colors hover:border-dynamic-azure/40 dark:border-stroke/25",children:[t.jsx(S,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),t.jsxs("span",{className:"min-w-0 flex-1 truncate text-[10px] font-medium",children:["Inspect JSON",s?` · ${s}`:""]}),t.jsx(J,{className:"h-2.5 w-2.5 shrink-0 text-muted-foreground"})]})}function L({value:e,path:s,name:r,depth:n,query:a,onCopy:i,copied:c}){const m=typeof e=="object"&&e!==null&&!Array.isArray(e),d=Array.isArray(e),[p,f]=x.useState(n<T),[h,g]=x.useState(N);if(!x.useMemo(()=>{if(a===""||r.toLowerCase().includes(a))return!0;try{return JSON.stringify(e).toLowerCase().includes(a)}catch{return!1}},[a,r,e]))return null;if(!m&&!d)return t.jsxs("div",{className:"group flex items-baseline gap-1.5 py-0.5",children:[r!==""&&t.jsxs("span",{className:"shrink-0 font-mono text-[9.5px] text-dynamic-azure",children:[r,":"]}),t.jsx(_,{value:e}),t.jsx(v,{path:s,value:e,onCopy:i,copied:c})]});const u=d?e.map((o,b)=>[String(b),o]):Object.entries(e),y=u.slice(0,h),k=u.length-y.length;return t.jsxs("div",{style:{paddingLeft:n===0?0:10},children:[t.jsxs("div",{className:"group flex items-baseline gap-1",children:[t.jsxs("button",{type:"button",onClick:()=>f(o=>!o),className:"flex min-w-0 items-baseline gap-1 text-left",children:[t.jsx(J,{className:A("h-2.5 w-2.5 shrink-0 self-center text-muted-foreground transition-transform",p&&"rotate-90")}),r!==""&&t.jsxs("span",{className:"shrink-0 font-mono text-[9.5px] text-dynamic-azure",children:[r,":"]}),t.jsx("span",{className:"shrink-0 font-mono text-[9.5px] text-muted-foreground",children:d?`Array(${String(u.length)})`:`{${String(u.length)}}`})]}),t.jsx(v,{path:s,value:e,onCopy:i,copied:c})]}),p&&t.jsxs(t.Fragment,{children:[y.map(([o,b])=>t.jsx(L,{value:b,path:s===""?o:d?`${s}[${o}]`:/^[A-Za-z_$][\w$]*$/.test(o)?`${s}.${o}`:`${s}["${o}"]`,name:o,depth:n+1,query:a,onCopy:i,copied:c},o)),k>0&&t.jsxs("button",{type:"button",onClick:()=>g(o=>o+N),style:{marginLeft:10},className:"mt-0.5 text-[9px] font-semibold text-dynamic-azure hover:underline",children:["Show ",String(Math.min(k,N))," more of ",String(u.length)]})]})]})}function _({value:e}){if(e===null)return t.jsx("span",{className:"font-mono text-[9.5px] text-muted-foreground",children:"null"});if(typeof e=="boolean")return t.jsx("span",{className:"font-mono text-[9.5px] text-tag-purple",children:String(e)});if(typeof e=="number")return t.jsx("span",{className:"font-mono text-[9.5px] text-tag-purple",children:String(e)});if(typeof e=="string"){const s=e.length>w;return t.jsxs("span",{className:"min-w-0 break-all font-mono text-[9.5px]",children:["“",s?e.slice(0,w):e,"”",s&&t.jsxs("span",{className:"text-muted-foreground",children:[" … ",String(e.length)," characters total"]})]})}return t.jsx("span",{className:"font-mono text-[9.5px] text-muted-foreground",children:String(e)})}function v({path:e,value:s,onCopy:r,copied:n}){const a=()=>{if(typeof s=="string")return s;try{return JSON.stringify(s,null,2)}catch{return String(s)}};return t.jsxs("span",{className:"ml-auto flex shrink-0 gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100",children:[t.jsx("button",{type:"button",onClick:()=>r(a(),`v:${e}`),title:"Copy value","aria-label":`Copy value at ${e===""?"root":e}`,className:"rounded px-1 text-[8.5px] font-semibold text-muted-foreground hover:bg-stroke/20 hover:text-foreground",children:n===`v:${e}`?t.jsx(j,{className:"h-2 w-2 text-emerald-600"}):"val"}),e!==""&&t.jsx("button",{type:"button",onClick:()=>r(e,`p:${e}`),title:`Copy path — ${e}`,"aria-label":`Copy path ${e}`,className:"rounded px-1 text-[8.5px] font-semibold text-muted-foreground hover:bg-stroke/20 hover:text-foreground",children:n===`p:${e}`?t.jsx(j,{className:"h-2 w-2 text-emerald-600"}):"path"})]})}function U(e){try{return{valid:!0,value:JSON.parse(e)}}catch(s){const r=s.message;if(/line \d+ column \d+/.test(r))return{valid:!1,error:r.replace(/ in JSON at position \d+ /," — ").replace(/[()]/g,"")};const n=/position (\d+)/.exec(r);if(n)return{valid:!1,error:`${r.replace(/ in JSON at position \d+/,"")} — ${$(e,Number(n[1]))}`};const i=/"([\s\S]*?)"(?:\.\.\.)?\s*is not valid JSON$/.exec(r)?.[1];if(i!==void 0&&i!==""){const c=e.indexOf(i);if(c>=0){const m=/Unexpected token (\S+?),/.exec(r)?.[1],d=m===void 0?c:c+Math.max(0,i.indexOf(P(m)));return{valid:!1,error:`${C(r)} — ${$(e,d)}`}}}return{valid:!1,error:C(r)}}}function $(e,s){const r=e.slice(0,Math.max(0,s)),n=r.split(`
`).length,a=s-r.lastIndexOf(`
`);return`line ${String(n)}, column ${String(a)}`}function P(e){return e.replace(/^['"]|['"]$/g,"")}function C(e){return e.replace(/,? \.\.\."[\s\S]*?"(?: is not valid JSON)?$/,"").replace(/ is not valid JSON$/,"").trim()}export{R as J,U as v};
//# sourceMappingURL=chunk-C73D8OYP.js.map
