import { jsx as _jsx } from "react/jsx-runtime";
import { useAtomValue } from 'jotai';
import { JsonViewer } from '@redocly/theme/components/JsonViewer/JsonViewer';
import { isFormUrlEncoded, isJsonLike, langFromMime, urlFormEncodePayload, } from '../../utils/index.js';
import { globalOptionsAtom } from '../../jotai/store.js';
import { StyledCodeBlock } from './styled.js';
export function ExampleValue({ value, mimeType, encoding, onCopyClick, onPanelToggle, }) {
    const { jsonSamplesExpandLevel } = useAtomValue(globalOptionsAtom);
    if (isJsonLike(mimeType)) {
        return (_jsx(JsonViewer, { data: value, expandLevel: jsonSamplesExpandLevel, onCopyClick: onCopyClick, onPanelToggle: onPanelToggle }));
    }
    if (typeof value === 'object') {
        if (isFormUrlEncoded(mimeType)) {
            value = urlFormEncodePayload(value, encoding);
        }
        else {
            // just in case example was cached as json but used as non-json
            value = JSON.stringify(value, null, 2);
        }
    }
    return (_jsx(StyledCodeBlock, { lang: langFromMime(mimeType), source: value, header: {
            className: 'code-block-header',
            controls: {
                copy: {
                    onClick: onCopyClick,
                },
            },
        } }));
}
//# sourceMappingURL=ExampleValue.js.map