import{jsx as i}from"react/jsx-runtime";import{useAtomValue as l}from"jotai";import{XMLBuilder as m}from"fast-xml-parser";import{JsonViewer as c}from"@redocly/theme/components/JsonViewer/JsonViewer";import{isFormUrlEncoded as d,isJsonLike as f,isXmlLike as p,langFromMime as x,urlFormEncodePayload as g,isSequentialMediaType as y}from"../../utils/index.js";import{globalOptionsAtom as j}from"../../jotai/store.js";import{StyledCodeBlock as k}from"./styled.js";const L=new m({format:!0,cdataPropName:"#cdata"});function B({value:o,mimeType:r,encoding:n,onCopyClick:e,onPanelToggle:s}){const{jsonSamplesExpandLevel:a}=l(j);if(f(r)&&!y(r)){let t;try{t=typeof o=="string"?JSON.parse(o):o}catch{t=o}return i(c,{data:t,expandLevel:a,onCopyClick:e,onPanelToggle:s})}if(typeof o=="object")if(d(r))o=g(o,n);else if(p(r)){const t=Array.isArray(o)?o:{root:o};o=L.build(t)}else o=JSON.stringify(o,null,2);return i(k,{lang:x(r),source:o,header:{className:"code-block-header",controls:{copy:{onClick:e}}}})}export{B as ExampleValue};
