import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import { ExampleValue, FieldLabel } from '../common/index.js';
import { tryDecodeURIComponent, normalizeText, serializeParameterValue, } from '../../utils/index.js';
import { ExampleWrap, ExamplesList, ExampleSummary } from './styled.js';
import { useTranslate } from '../../hooks/index.js';
import { Markdown } from '../Markdown/index.js';
export function Examples({ field }) {
    const translate = useTranslate();
    if (!field.examples) {
        return null;
    }
    return (_jsxs(_Fragment, { children: [_jsxs(FieldLabel, { children: [" ", translate('openapi.examples', 'Examples'), ": "] }), _jsx(ExamplesList, { children: Object.entries(field.examples).map(([id, example]) => {
                    const description = normalizeText(example.description);
                    return (_jsxs(ExampleWrap, { children: [_jsxs(ExampleSummary, { children: [normalizeText(example.summary) || id, " "] }), description && _jsx(Markdown, { source: description }), _jsx(ExampleValue, { children: getSerializedValue(field, example.value) })] }, id));
                }) })] }));
}
export function getSerializedValue(field, example) {
    if (field.in) {
        // decode for better readability in examples: see https://github.com/Redocly/redoc/issues/1138
        return tryDecodeURIComponent(serializeParameterValue(field, example));
    }
    else {
        return example;
    }
}
//# sourceMappingURL=Examples.js.map