import { jsx as _jsx } from "react/jsx-runtime";
import { createElement } from 'react';
import { createRoot, hydrateRoot } from 'react-dom/client';
import { querySelector } from './utils/dom.js';
import { RedoclyOpenAPIDocs } from './components/RedoclyOpenAPIDocs/RedoclyOpenAPIDocs.js';
import { RedoclyOpenAPIDocsStandalone } from './components/RedoclyOpenAPIDocs/RedoclyOpenAPIDocsStandalone.js';
export { setSecurityDetails, setSecurityDetailsVariants } from './utils/security-details.js';
export { setParameterValue } from './utils/parameters.js';
function attributesMap(element) {
    const res = {};
    const elAttrs = element.attributes;
    // tslint:disable-next-line
    for (let i = 0; i < elAttrs.length; i++) {
        const attrib = elAttrs[i];
        res[attrib.name] = attrib.value;
    }
    return res;
}
function parseOptionsFromElement(element) {
    const attrMap = attributesMap(element);
    const res = {};
    for (const attrName in attrMap) {
        const optionName = attrName.replace(/-(.)/g, (_, $1) => $1.toUpperCase());
        res[optionName] = attrMap[attrName];
        // TODO: normalize options
    }
    return res;
}
export function hydrate(store, element = document.querySelector('redoc')) {
    // const store = ProStore.fromJS(state);
    hydrateRoot(element, _jsx(RedoclyOpenAPIDocs, { store: store }));
}
export function init(definitionOrDefinitionUrl, options = {}, element = querySelector('redoc')) {
    if (element === null) {
        throw new Error('"element" argument is not provided and <redoc> tag is not found on the page');
    }
    let definitionUrl;
    let definition;
    if (typeof definitionOrDefinitionUrl === 'string') {
        definitionUrl = definitionOrDefinitionUrl;
    }
    else if (typeof definitionOrDefinitionUrl === 'object') {
        definition = definitionOrDefinitionUrl;
    }
    const root = createRoot(element);
    root.render(createElement(RedoclyOpenAPIDocsStandalone, {
        definition,
        definitionUrl,
        options: { ...options, ...parseOptionsFromElement(element) },
    }, ['Loading...']));
}
export const version = __REDOCLY_API_REFERENCE_VERSION__;
export const revision = __REDOCLY_API_REFERENCE_REVISION__;
/**
 * autoinit ReDoc if <redoc> tag is found on the page with "spec-url" attr
 */
function autoInit() {
    const element = querySelector('redoc');
    if (!element) {
        return;
    }
    const specUrl = element.getAttribute('spec-url');
    if (specUrl) {
        init(specUrl, {}, element);
    }
}
autoInit();
//# sourceMappingURL=standalone.js.map