import{p as e}from"./nc-util.BWncs0l6.js";import{Fragment as t,computed as n,createCommentVNode as r,createElementBlock as i,createElementVNode as a,createTextVNode as o,createVNode as s,normalizeClass as c,normalizeStyle as l,openBlock as u,ref as d,renderList as f,renderSlot as p,resolveComponent as m,toDisplayString as h,unref as g,vShow as _,watch as v,withDirectives as y}from"/vue.js";var b={class:`nc-json-line`},x=[`onClick`],S={key:0,class:`nc-json-k`},C={class:`nc-json-line`},w={class:`nc-json-k`},T=[`onClick`],E={key:0,class:`nc-json-k`},D={class:`nc-json-line`},O={class:`nc-json-k`},k={key:0,class:`nc-json-k`},A=Object.assign({name:`NcJsonTree`},{__name:`nc-json-tree`,props:{data:{type:Array,default:()=>[]},showLeaf:{type:Boolean,default:!0},indent:{type:Number,default:1},needKey:{type:Boolean,default:!0}},setup(e){let o=e,d=n(()=>({textIndent:`${(o.indent+1)*20}px`}));function v(e){e.show=!e.show}function A(e){return e===`Object`}function j(e){return e===`Array`}function M(e){return e===o.data.length-1?``:`,`}function N(e){return e===`Number`?`nc-json-number`:e===`String`?`nc-json-string`:e===`Boolean`?`nc-json-boolean`:e===`Undefined`?`nc-json-undefined`:e===`Null`?`nc-json-null`:``}return(n,o)=>{let P=m(`nc-json-tree`,!0);return u(),i(`div`,null,[(u(!0),i(t,null,f(e.data,(t,f)=>(u(),i(`p`,{key:f,class:`nc-json-p`,style:l(g(d))},[a(`span`,b,h(t.line),1),A(t.type)?p(n.$slots,`default`,{key:0},()=>[a(`p`,{class:`nc-json-f`,onClick:e=>v(t)},[e.needKey?(u(),i(`span`,S,`"`+h(t.key)+`": `,1)):r(``,!0),o[0]||(o[0]=a(`span`,{class:`nc-json-k`},`{`,-1)),y(a(`span`,{class:`nc-json-k`},` ... } `+h(M(f)),513),[[_,!t.show]])],8,x),y(s(P,{data:t.value,"show-leaf":!1,indent:e.indent+1,"need-key":!0},null,8,[`data`,`indent`]),[[_,t.show]]),y(a(`p`,{style:l(g(d)),class:`nc-json-p`},[a(`span`,C,h(t.lastLine),1),a(`span`,w,`} `+h(M(f)),1)],4),[[_,t.show]])]):j(t.type)?p(n.$slots,`default`,{key:1},()=>[a(`p`,{class:`nc-json-f`,onClick:e=>v(t)},[e.needKey?(u(),i(`span`,E,`"`+h(t.key)+`": `,1)):r(``,!0),o[1]||(o[1]=a(`span`,{class:`nc-json-k`},`[`,-1)),y(a(`span`,{class:`nc-json-k`},` ... ] `+h(M(f)),513),[[_,!t.show]])],8,T),y(s(P,{data:t.value,"show-leaf":!1,indent:e.indent+1,"need-key":!1},null,8,[`data`,`indent`]),[[_,t.show]]),y(a(`p`,{style:l(g(d)),class:`nc-json-p`},[a(`span`,D,h(t.lastLine),1),a(`span`,O,`] `+h(M(f)),1)],4),[[_,t.show]])]):p(n.$slots,`default`,{key:2},()=>[e.needKey?(u(),i(`span`,k,`"`+h(t.key)+`": `,1)):r(``,!0),a(`span`,{class:c(N(t.type))},h(t.value)+h(M(f)),3)])],4))),128))])}}}),j=1,M=t=>{j=1;let n=[];if(e.isObject(t))n=N(t);else if(e.isArray(t))n=P(t);else return[{key:``,value:`error: data should be an Object or Array type`,type:`String`,line:`1`}];return n},N=t=>{let n=[];for(let r in t){let i=Object.create(null);i.type=e.type(t[r]),i.line=j++,i.key=r,e.isObject(t[r])?(i.value=N(t[r]),i.lastLine=j++,i.show=!0):e.isArray(t[r])?(i.value=P(t[r]),i.lastLine=j++,i.show=!0):t[r]==null?i.value=`null`:t[r]===void 0?i.value=`undefined`:e.isString(t[r])?i.value=`"`+t[r]+`"`:i.value=t[r],n.push(i)}return n},P=t=>{let n=[];for(let r=0;r<t.length;r++){let i=Object.create(null);i.type=e.type(t[r]),i.key=r,i.line=j++,e.isObject(t[r])?(i.value=N(t[r]),i.lastLine=j++,i.show=!0):e.isArray(t[r])?(i.value=P(t[r]),i.lastLine=j++,i.show=!0):t[r]==null?i.value=`null`:t[r]===void 0?i.value=`undefined`:e.isString(t[r])?i.value=`"`+t[r]+`"`:i.value=t[r],n.push(i)}return n},F={class:`nc-json`},I={key:2},L={key:3},R=Object.assign({name:`NcJson`},{__name:`nc-json`,props:{data:{type:[Object,Array,String],default:()=>{}}},setup(t){let n=t,r=d({}),c=d([]),l=d(!0),f=d(!0),m=d(!1);return v(()=>n.data,()=>{if(m.value=!1,e.isString(n.data)){let e;try{e=JSON.parse(n.data)}catch(e){f.value=!1;return}r.value=e}else r.value=n.data;e.isObject(r.value)?(f.value=!0,m.value=!0):e.isArray(r.value)?(f.value=!1,m.value=!0):f.value=!1,m.value&&(c.value=M(r.value))},{immediate:!0}),(e,n)=>(u(),i(`code`,F,[a(`div`,null,[g(m)?p(e.$slots,`default`,{key:0},()=>[g(f)?(u(),i(`p`,{key:0,class:`nc-json-f`,onClick:n[0]||(n[0]=e=>l.value=!g(l))},[n[2]||(n[2]=o(` { `,-1)),y(a(`span`,null,`... }`,512),[[_,!g(l)]])])):(u(),i(`p`,{key:1,class:`nc-json-f`,onClick:n[1]||(n[1]=e=>l.value=!g(l))},[n[3]||(n[3]=o(` [ `,-1)),y(a(`span`,null,`... ]`,512),[[_,!g(l)]])])),y(s(A,{data:g(c),"need-key":g(f)},null,8,[`data`,`need-key`]),[[_,g(l)]]),g(f)?y((u(),i(`p`,I,`}`,512)),[[_,g(l)]]):y((u(),i(`p`,L,`]`,512)),[[_,g(l)]])]):p(e.$slots,`default`,{key:1},()=>[o(h(t.data),1)])])]))}});export{R as default};