import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useMemo } from 'react';
import { Markdown as MarkdownWrapper } from '@redocly/theme/components/Markdown/Markdown';
import { H3 } from '@redocly/theme/components/Typography/H3';
import { isNotNull } from '@redocly/theme/core/openapi';
const FILTER_OUT_KEYS = ['title', 'description']; // We don't want to show these keys
function metadataMap([key, value]) {
    if (FILTER_OUT_KEYS.includes(key)) {
        return null;
    }
    if (Array.isArray(value)) {
        return { key, value: value.filter((val) => typeof val !== 'object').join(', ') };
    }
    // We don't want to show objects
    if (typeof value === 'object') {
        return null;
    }
    return { key, value };
}
export function Metadata({ metadata, translate }) {
    const filteredMetadata = useMemo(() => Object.entries(metadata || {})
        .map(metadataMap)
        .filter(isNotNull), [metadata]);
    if (!metadata) {
        return null;
    }
    return (_jsxs(MarkdownWrapper, { children: [_jsx(H3, { children: translate('openapi.info.metadata.title', 'Metadata') }), _jsxs("table", { className: "md", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: translate('openapi.key', 'Key') }), _jsx("th", { scope: "col", children: translate('openapi.value', 'Value') })] }) }), _jsx("tbody", { children: filteredMetadata.map(({ key, value }) => (_jsxs("tr", { children: [_jsx("td", { children: key }), _jsx("td", { children: `${value}` })] }, key))) })] })] }));
}
//# sourceMappingURL=Metadata.js.map