import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { ParametersGroup } from './ParametersGroup.js';
import { Body } from './Body.js';
import { makeDeepLink } from '../../services/index.js';
import { useTranslate } from '../../hooks/index.js';
const PARAM_PLACES = ['path', 'query', 'cookie', 'header'];
export function RequestParameters({ body, parameters = [], operationId, callbackId, }) {
    const translate = useTranslate();
    if (!body && !parameters.length) {
        return null;
    }
    const PARAM_NAMES_MAP = {
        [PARAM_PLACES[0]]: translate('openapi.path', 'Path'),
        [PARAM_PLACES[1]]: translate('openapi.query', 'Query'),
        [PARAM_PLACES[2]]: translate('openapi.cookie', 'Cookies'),
        [PARAM_PLACES[3]]: translate('openapi.header', 'Headers'),
    };
    const orderParams = (params) => {
        const res = {};
        params.forEach((param) => {
            safePush(res, param.in, param);
        });
        return res;
    };
    const paramsMap = orderParams(parameters);
    const paramsPlaces = parameters.length > 0 ? PARAM_PLACES : [];
    const { content: bodyContent, description: bodyDescription, required } = body || {};
    return (_jsxs(_Fragment, { children: [paramsPlaces.map((place) => (_jsx(ParametersGroup, { title: PARAM_NAMES_MAP[place], parameters: paramsMap[place], deepLink: generateDeepLink(operationId, callbackId, place) }, place))), bodyContent && (_jsx(Body, { content: bodyContent, description: bodyDescription, required: required, deepLink: generateDeepLink(operationId, callbackId) }))] }));
}
function safePush(obj, prop = '', item) {
    if (!obj[prop]) {
        obj[prop] = [];
    }
    obj[prop].push(item);
}
function generateDeepLink(operationId, callbackId, place = 'body') {
    const suffix = `${callbackId ? `${callbackId}/request/${place}` : `request/${place}`}`;
    return makeDeepLink(operationId, suffix);
}
//# sourceMappingURL=RequestParameters.js.map