import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { memo, useMemo } from 'react';
import { useAtomValue } from 'jotai';
import { Row } from '../common/index.js';
import { Title } from '../common/OperationItemTitle.js';
import { LinkToField } from '../common/LinkToField.js';
import { makeDeepLink } from '../../services/index.js';
import { Description } from '../OperationItem/Description.js';
import { Security } from '../Security/index.js';
import { ExpandAllButton } from '../ExpandAllButton/index.js';
import { RequestParameters } from '../RequestParameters/index.js';
import { activeMimeNameAtom } from '../../jotai/app.js';
import { getActiveMediaType } from '../../models/mediaContent.js';
import { styled } from '../../styled-components.js';
import { Extensions } from '../common/Extensions.js';
function RequestDetailsComponent({ operation: { id, description, externalDocs, parameters, requestBody, pointer, security, extensions, callbackId, }, title, translate, onPanelToggle, }) {
    const activeMimeName = useAtomValue(activeMimeNameAtom);
    const showExpandAllButton = useMemo(() => {
        const hasNestedParameters = parameters.some(({ schema }) => !schema.isPrimitive && !schema.isCircular);
        if (!requestBody?.content || hasNestedParameters) {
            return hasNestedParameters;
        }
        const { schema } = getActiveMediaType(requestBody.content, activeMimeName) || {};
        const hasNestedRequestBody = schema?.fields?.some(({ schema: fieldSchema }) => !fieldSchema.isPrimitive && !fieldSchema.isCircular);
        return hasNestedRequestBody;
    }, [activeMimeName, parameters, requestBody?.content]);
    const hasCustomExtensions = Object.keys(extensions || {}).length > 0;
    return (_jsxs(_Fragment, { children: [_jsx(Row, { children: _jsxs(HeadingWrapper, { children: [_jsxs(Title, { children: [id && _jsx(LinkToField, { to: makeDeepLink(id, 'request') }), title || translate?.('openapi.request', 'Request'), showExpandAllButton && (_jsx(ExpandAllButton, { operationPointer: pointer, type: "request", onPanelToggle: onPanelToggle }))] }), _jsx(Description, { description: description || externalDocs ? description : undefined, externalDocs: externalDocs }), hasCustomExtensions && _jsx(Extensions, { extensions: extensions }), _jsx(Security, { securities: security })] }) }), _jsx(RequestParameters, { parameters: parameters, body: requestBody, operationId: id, callbackId: callbackId })] }));
}
const HeadingWrapper = styled.div `
  width: 100%;
`;
export const RequestDetails = memo(RequestDetailsComponent);
//# sourceMappingURL=RequestDetails.js.map