import { jsx as _jsx } from "react/jsx-runtime";
import { memo, useCallback } from 'react';
import { useAtomValue } from 'jotai';
import { SelectOrLabel } from '../SelectOrLabel/index.js';
import { MediaTypesSwitch } from '../MediaTypeSwitch/index.js';
import { MimeLabel, Select } from '../common/index.js';
import { MediaTypeSamples } from './MediaTypeSamples.js';
import { SelectWrapper, StyledCodeBlock } from './styled.js';
import { activeMimeNameAtom } from '../../jotai/app.js';
import { useActivateExample, useTranslate } from '../../hooks/index.js';
function PayloadSamplesComponent({ onlyDefaultMimeType, content: mimeContent, ...props }) {
    const setActivateExampleName = useActivateExample(mimeContent);
    const defaultMimeType = useAtomValue(activeMimeNameAtom); // we pass defaultMimeType from portal
    const showDefaultMimeType = onlyDefaultMimeType && defaultMimeType;
    const translate = useTranslate();
    const renderSelect = useCallback((props) => {
        return showDefaultMimeType ? null : (_jsx(SelectWrapper, { children: _jsx(SelectOrLabel, { Label: MimeLabel, Select: Select, variant: "dark", fullWidth: true, ...props }) }));
    }, [showDefaultMimeType]);
    const handleMediaTypeChange = (key) => setActivateExampleName(key);
    if (!mimeContent) {
        return (_jsx(StyledCodeBlock, { lang: "text", source: translate('openapi.noRequestPayload', 'No request payload'), header: { controls: false } }));
    }
    return (_jsx(MediaTypesSwitch, { content: mimeContent, renderSelect: renderSelect, children: (mediaType) => (_jsx(MediaTypeSamples, { mediaType: mediaType, ...props, onChange: handleMediaTypeChange }, "samples")) }));
}
export const PayloadSamples = memo(PayloadSamplesComponent);
//# sourceMappingURL=PayloadSamples.js.map