import { __esDecorate, __runInitializers } from "tslib";
import { html } from 'lit';
import { property } from 'lit/decorators.js';
import { AmfNamespace } from '@api-client/core/amf/definitions/Namespace.js';
import { ApiDocumentationBase } from './ApiDocumentationBase.js';
import { EventTypes } from '../../events/amf/EventTypes.js';
import { Events } from '../../events/amf/Events.js';
import '../../define/amf/api-summary.js';
import '../../define/amf/api-operation-document.js';
import '../../define/amf/api-resource-document.js';
import '../../define/amf/api-security-document.js';
import '../../define/amf/api-documentation-document.js';
import '../../define/amf/api-schema-document.js';
import '../../define/amf/api-server-picker.js';
import '../../md/radio/ui-radio.js';
let ApiDocumentation = (() => {
    let _classSuper = ApiDocumentationBase;
    let _instanceExtraInitializers = [];
    let _baseUri_decorators;
    let _baseUri_initializers = [];
    let _baseUri_extraInitializers = [];
    let _tryItButton_decorators;
    let _tryItButton_initializers = [];
    let _tryItButton_extraInitializers = [];
    let _tryItPanel_decorators;
    let _tryItPanel_initializers = [];
    let _tryItPanel_extraInitializers = [];
    let _redirectUri_decorators;
    let _redirectUri_initializers = [];
    let _redirectUri_extraInitializers = [];
    let _httpUrlEditor_decorators;
    let _httpUrlEditor_initializers = [];
    let _httpUrlEditor_extraInitializers = [];
    let _httpApplyAuthorization_decorators;
    let _httpApplyAuthorization_initializers = [];
    let _httpApplyAuthorization_extraInitializers = [];
    let _httpCredentialsSource_decorators;
    let _httpCredentialsSource_initializers = [];
    let _httpCredentialsSource_extraInitializers = [];
    let _noServerSelector_decorators;
    let _noServerSelector_initializers = [];
    let _noServerSelector_extraInitializers = [];
    let _httpAllowCustom_decorators;
    let _httpAllowCustom_initializers = [];
    let _httpAllowCustom_extraInitializers = [];
    let _allowCustomBaseUri_decorators;
    let _allowCustomBaseUri_initializers = [];
    let _allowCustomBaseUri_extraInitializers = [];
    let _serverValue_decorators;
    let _serverValue_initializers = [];
    let _serverValue_extraInitializers = [];
    let _serverType_decorators;
    let _serverType_initializers = [];
    let _serverType_extraInitializers = [];
    let _schemaMimeType_decorators;
    let _schemaMimeType_initializers = [];
    let _schemaMimeType_extraInitializers = [];
    let _set_domainType_decorators;
    let _set_operationId_decorators;
    let _set_handleNavigationEvents_decorators;
    return class ApiDocumentation extends _classSuper {
        static {
            const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
            _baseUri_decorators = [property({ type: String })];
            _tryItButton_decorators = [property({ type: Boolean, reflect: true })];
            _tryItPanel_decorators = [property({ type: Boolean, reflect: true })];
            _redirectUri_decorators = [property({ type: String })];
            _httpUrlEditor_decorators = [property({ type: Boolean, reflect: true })];
            _httpApplyAuthorization_decorators = [property({ type: Boolean, reflect: true })];
            _httpCredentialsSource_decorators = [property({ type: Array })];
            _noServerSelector_decorators = [property({ type: Boolean, reflect: true })];
            _httpAllowCustom_decorators = [property({ type: Boolean, reflect: true })];
            _allowCustomBaseUri_decorators = [property({ type: Boolean, reflect: true })];
            _serverValue_decorators = [property({ type: String })];
            _serverType_decorators = [property({ type: String })];
            _schemaMimeType_decorators = [property({ type: String })];
            _set_domainType_decorators = [property({ type: String, reflect: true })];
            _set_operationId_decorators = [property({ type: String, reflect: true })];
            _set_handleNavigationEvents_decorators = [property({ type: Boolean, reflect: true })];
            __esDecorate(this, null, _baseUri_decorators, { kind: "accessor", name: "baseUri", static: false, private: false, access: { has: obj => "baseUri" in obj, get: obj => obj.baseUri, set: (obj, value) => { obj.baseUri = value; } }, metadata: _metadata }, _baseUri_initializers, _baseUri_extraInitializers);
            __esDecorate(this, null, _tryItButton_decorators, { kind: "accessor", name: "tryItButton", static: false, private: false, access: { has: obj => "tryItButton" in obj, get: obj => obj.tryItButton, set: (obj, value) => { obj.tryItButton = value; } }, metadata: _metadata }, _tryItButton_initializers, _tryItButton_extraInitializers);
            __esDecorate(this, null, _tryItPanel_decorators, { kind: "accessor", name: "tryItPanel", static: false, private: false, access: { has: obj => "tryItPanel" in obj, get: obj => obj.tryItPanel, set: (obj, value) => { obj.tryItPanel = value; } }, metadata: _metadata }, _tryItPanel_initializers, _tryItPanel_extraInitializers);
            __esDecorate(this, null, _redirectUri_decorators, { kind: "accessor", name: "redirectUri", static: false, private: false, access: { has: obj => "redirectUri" in obj, get: obj => obj.redirectUri, set: (obj, value) => { obj.redirectUri = value; } }, metadata: _metadata }, _redirectUri_initializers, _redirectUri_extraInitializers);
            __esDecorate(this, null, _httpUrlEditor_decorators, { kind: "accessor", name: "httpUrlEditor", static: false, private: false, access: { has: obj => "httpUrlEditor" in obj, get: obj => obj.httpUrlEditor, set: (obj, value) => { obj.httpUrlEditor = value; } }, metadata: _metadata }, _httpUrlEditor_initializers, _httpUrlEditor_extraInitializers);
            __esDecorate(this, null, _httpApplyAuthorization_decorators, { kind: "accessor", name: "httpApplyAuthorization", static: false, private: false, access: { has: obj => "httpApplyAuthorization" in obj, get: obj => obj.httpApplyAuthorization, set: (obj, value) => { obj.httpApplyAuthorization = value; } }, metadata: _metadata }, _httpApplyAuthorization_initializers, _httpApplyAuthorization_extraInitializers);
            __esDecorate(this, null, _httpCredentialsSource_decorators, { kind: "accessor", name: "httpCredentialsSource", static: false, private: false, access: { has: obj => "httpCredentialsSource" in obj, get: obj => obj.httpCredentialsSource, set: (obj, value) => { obj.httpCredentialsSource = value; } }, metadata: _metadata }, _httpCredentialsSource_initializers, _httpCredentialsSource_extraInitializers);
            __esDecorate(this, null, _noServerSelector_decorators, { kind: "accessor", name: "noServerSelector", static: false, private: false, access: { has: obj => "noServerSelector" in obj, get: obj => obj.noServerSelector, set: (obj, value) => { obj.noServerSelector = value; } }, metadata: _metadata }, _noServerSelector_initializers, _noServerSelector_extraInitializers);
            __esDecorate(this, null, _httpAllowCustom_decorators, { kind: "accessor", name: "httpAllowCustom", static: false, private: false, access: { has: obj => "httpAllowCustom" in obj, get: obj => obj.httpAllowCustom, set: (obj, value) => { obj.httpAllowCustom = value; } }, metadata: _metadata }, _httpAllowCustom_initializers, _httpAllowCustom_extraInitializers);
            __esDecorate(this, null, _allowCustomBaseUri_decorators, { kind: "accessor", name: "allowCustomBaseUri", static: false, private: false, access: { has: obj => "allowCustomBaseUri" in obj, get: obj => obj.allowCustomBaseUri, set: (obj, value) => { obj.allowCustomBaseUri = value; } }, metadata: _metadata }, _allowCustomBaseUri_initializers, _allowCustomBaseUri_extraInitializers);
            __esDecorate(this, null, _serverValue_decorators, { kind: "accessor", name: "serverValue", static: false, private: false, access: { has: obj => "serverValue" in obj, get: obj => obj.serverValue, set: (obj, value) => { obj.serverValue = value; } }, metadata: _metadata }, _serverValue_initializers, _serverValue_extraInitializers);
            __esDecorate(this, null, _serverType_decorators, { kind: "accessor", name: "serverType", static: false, private: false, access: { has: obj => "serverType" in obj, get: obj => obj.serverType, set: (obj, value) => { obj.serverType = value; } }, metadata: _metadata }, _serverType_initializers, _serverType_extraInitializers);
            __esDecorate(this, null, _schemaMimeType_decorators, { kind: "accessor", name: "schemaMimeType", static: false, private: false, access: { has: obj => "schemaMimeType" in obj, get: obj => obj.schemaMimeType, set: (obj, value) => { obj.schemaMimeType = value; } }, metadata: _metadata }, _schemaMimeType_initializers, _schemaMimeType_extraInitializers);
            __esDecorate(this, null, _set_domainType_decorators, { kind: "setter", name: "domainType", static: false, private: false, access: { has: obj => "domainType" in obj, set: (obj, value) => { obj.domainType = value; } }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _set_operationId_decorators, { kind: "setter", name: "operationId", static: false, private: false, access: { has: obj => "operationId" in obj, set: (obj, value) => { obj.operationId = value; } }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _set_handleNavigationEvents_decorators, { kind: "setter", name: "handleNavigationEvents", static: false, private: false, access: { has: obj => "handleNavigationEvents" in obj, set: (obj, value) => { obj.handleNavigationEvents = value; } }, metadata: _metadata }, null, _instanceExtraInitializers);
            if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
        }
        domainTypeValue = __runInitializers(this, _instanceExtraInitializers);
        operationIdValue;
        handleNavigationEventsValue;
        renderedViewValue;
        apiSummaryValue;
        documentMetaValue;
        navEventsRegistered;
        #baseUri_accessor_storage = __runInitializers(this, _baseUri_initializers, void 0);
        /**
         * A property to set to override AMF's model base URI information.
         * @attribute
         */
        get baseUri() { return this.#baseUri_accessor_storage; }
        set baseUri(value) { this.#baseUri_accessor_storage = value; }
        #tryItButton_accessor_storage = (__runInitializers(this, _baseUri_extraInitializers), __runInitializers(this, _tryItButton_initializers, void 0));
        /**
         * When set it renders the "try it" button that dispatches the `tryit` event.
         * @attribute
         */
        get tryItButton() { return this.#tryItButton_accessor_storage; }
        set tryItButton(value) { this.#tryItButton_accessor_storage = value; }
        #tryItPanel_accessor_storage = (__runInitializers(this, _tryItButton_extraInitializers), __runInitializers(this, _tryItPanel_initializers, void 0));
        /**
         * When set it renders the "try it" panel next to the operation documentation.
         * Setting this automatically disables the `tryItButton` property.
         *
         * Note, use this only when there's enough space on the screen to render 2 panels side-by-side.
         * @attribute
         */
        get tryItPanel() { return this.#tryItPanel_accessor_storage; }
        set tryItPanel(value) { this.#tryItPanel_accessor_storage = value; }
        #redirectUri_accessor_storage = (__runInitializers(this, _tryItPanel_extraInitializers), __runInitializers(this, _redirectUri_initializers, void 0));
        /**
         * OAuth2 redirect URI.
         * This value **must** be set in order for OAuth 1/2 to work properly.
         * This is only required in inline mode (`inlineMethods`).
         * @attribute
         */
        get redirectUri() { return this.#redirectUri_accessor_storage; }
        set redirectUri(value) { this.#redirectUri_accessor_storage = value; }
        #httpUrlEditor_accessor_storage = (__runInitializers(this, _redirectUri_extraInitializers), __runInitializers(this, _httpUrlEditor_initializers, void 0));
        /**
         * When set it renders the URL input above the URL parameters in the HTTP editor.
         * @attribute
         */
        get httpUrlEditor() { return this.#httpUrlEditor_accessor_storage; }
        set httpUrlEditor(value) { this.#httpUrlEditor_accessor_storage = value; }
        #httpApplyAuthorization_accessor_storage = (__runInitializers(this, _httpUrlEditor_extraInitializers), __runInitializers(this, _httpApplyAuthorization_initializers, void 0));
        /**
         * When set it applies the authorization values to the request dispatched
         * with the API request event.
         * If possible, it applies the authorization values to query parameter or headers
         * depending on the configuration.
         *
         * When the values arr applied to the request the authorization config is kept in the
         * request object, but its `enabled` state is always `false`, meaning other potential
         * processors should ignore this values.
         *
         * If this property is not set then the application hosting this component should
         * process the authorization data and apply them to the request.
         * @attribute
         */
        get httpApplyAuthorization() { return this.#httpApplyAuthorization_accessor_storage; }
        set httpApplyAuthorization(value) { this.#httpApplyAuthorization_accessor_storage = value; }
        #httpCredentialsSource_accessor_storage = (__runInitializers(this, _httpApplyAuthorization_extraInitializers), __runInitializers(this, _httpCredentialsSource_initializers, void 0));
        /**
         * List of credentials source passed to the HTTP editor
         */
        get httpCredentialsSource() { return this.#httpCredentialsSource_accessor_storage; }
        set httpCredentialsSource(value) { this.#httpCredentialsSource_accessor_storage = value; }
        #noServerSelector_accessor_storage = (__runInitializers(this, _httpCredentialsSource_extraInitializers), __runInitializers(this, _noServerSelector_initializers, void 0));
        /**
         * Optional property to set on the request editor.
         * When true, the server selector is not rendered
         * @attribute
         */
        get noServerSelector() { return this.#noServerSelector_accessor_storage; }
        set noServerSelector(value) { this.#noServerSelector_accessor_storage = value; }
        #httpAllowCustom_accessor_storage = (__runInitializers(this, _noServerSelector_extraInitializers), __runInitializers(this, _httpAllowCustom_initializers, void 0));
        /**
         * When set it renders "add custom" item button in the HTTP request editor.
         * If the element is to be used without AMF model this should always
         * be enabled. Otherwise users won't be able to add a parameter.
         * @attribute
         */
        get httpAllowCustom() { return this.#httpAllowCustom_accessor_storage; }
        set httpAllowCustom(value) { this.#httpAllowCustom_accessor_storage = value; }
        #allowCustomBaseUri_accessor_storage = (__runInitializers(this, _httpAllowCustom_extraInitializers), __runInitializers(this, _allowCustomBaseUri_initializers, void 0));
        /**
         * Optional property to set on the request editor.
         * If true, the server selector custom base URI option is rendered
         * @attribute
         */
        get allowCustomBaseUri() { return this.#allowCustomBaseUri_accessor_storage; }
        set allowCustomBaseUri(value) { this.#allowCustomBaseUri_accessor_storage = value; }
        #serverValue_accessor_storage = (__runInitializers(this, _allowCustomBaseUri_extraInitializers), __runInitializers(this, _serverValue_initializers, void 0));
        /**
         * The URI of the server currently selected in the server selector
         * @attribute
         */
        get serverValue() { return this.#serverValue_accessor_storage; }
        set serverValue(value) { this.#serverValue_accessor_storage = value; }
        #serverType_accessor_storage = (__runInitializers(this, _serverValue_extraInitializers), __runInitializers(this, _serverType_initializers, void 0));
        /**
         * The type of the server currently selected in the server selector
         * @attribute
         */
        get serverType() { return this.#serverType_accessor_storage; }
        set serverType(value) { this.#serverType_accessor_storage = value; }
        #schemaMimeType_accessor_storage = (__runInitializers(this, _serverType_extraInitializers), __runInitializers(this, _schemaMimeType_initializers, void 0));
        /**
         * The mime type of the currently selected schema.
         * @attribute
         */
        get schemaMimeType() { return this.#schemaMimeType_accessor_storage; }
        set schemaMimeType(value) { this.#schemaMimeType_accessor_storage = value; }
        serversCount = __runInitializers(this, _schemaMimeType_extraInitializers);
        /**
         * The type of the selected domain item.
         * @attribute
         */
        get domainType() {
            return this.domainTypeValue;
        }
        set domainType(value) {
            const old = this.domainTypeValue;
            if (old === value) {
                return;
            }
            this.domainTypeValue = value;
            this.requestUpdate('domainType', old);
            if (value) {
                this.processDebounce();
            }
        }
        /**
         * The domain id of the currently rendered API operation.
         * When selecting an operation the `domainId` is the id if the parent endpoint.
         * @attribute
         */
        get operationId() {
            return this.operationIdValue;
        }
        set operationId(value) {
            const old = this.operationIdValue;
            if (old === value) {
                return;
            }
            this.operationIdValue = value;
            this.requestUpdate('operationId', old);
            if (value) {
                this.processDebounce();
            }
        }
        /**
         * By default application hosting the element must set `domainId` and
         * `domainType` properties. When using `api-navigation` element
         * by setting this property the element listens for navigation events
         * and updates the state
         * @attribute
         */
        get handleNavigationEvents() {
            return this.handleNavigationEventsValue;
        }
        set handleNavigationEvents(value) {
            const old = this.handleNavigationEventsValue;
            if (old === value) {
                return;
            }
            this.handleNavigationEventsValue = value;
            if (value) {
                this.registerNavigationEvents();
            }
            else {
                this.unregisterNavigationEvents();
            }
        }
        /**
         * Former `effectiveBaseUri`.
         * @returns The URI for the API defined by the `baseUri` property or the `serverValue`.
         */
        get apiBaseUri() {
            const { baseUri, serverValue } = this;
            return baseUri || serverValue;
        }
        /**
         * @deprecated Use `apiBaseUri` instead.
         */
        get effectiveBaseUri() {
            return this.apiBaseUri;
        }
        /** The domain type of the rendered view. */
        get renderedView() {
            return this.renderedViewValue;
        }
        get renderSelector() {
            const { domainType, serversCount = 0, allowCustomBaseUri } = this;
            const isOperationOrEndpoint = !!domainType && ['operation', 'resource'].includes(domainType);
            const moreThanOneServer = serversCount >= 2;
            if (isOperationOrEndpoint) {
                return allowCustomBaseUri || moreThanOneServer;
            }
            return false;
        }
        /**
         * This is a computed value from the AMF model.
         * @returns true when whe currently loaded API is an async API.
         */
        get isAsync() {
            const { documentMeta } = this;
            if (!documentMeta) {
                return false;
            }
            return documentMeta.isAsync;
        }
        /**
         * @returns The mime type of the schema that is being rendered.
         */
        get schemaMime() {
            const { schemaMimeType } = this;
            if (schemaMimeType) {
                return schemaMimeType;
            }
            const summary = this.apiSummaryValue;
            if (!summary) {
                return undefined;
            }
            const { accepts = [] } = summary;
            if (!accepts.length) {
                return undefined;
            }
            return accepts[0];
        }
        get documentMeta() {
            return this.documentMetaValue;
        }
        constructor() {
            super();
            this.navigationHandler = this.navigationHandler.bind(this);
            this.navEventsRegistered = false;
        }
        connectedCallback() {
            super.connectedCallback();
            this.processDebounce();
        }
        disconnectedCallback() {
            super.disconnectedCallback();
            if (this.navEventsRegistered) {
                this.unregisterNavigationEvents();
            }
        }
        /**
         * Registers the api navigation event listener handler
         * on the window object.
         */
        registerNavigationEvents() {
            this.navEventsRegistered = true;
            window.addEventListener(EventTypes.Navigation.apiNavigate, this.navigationHandler);
        }
        /**
         * Removes event listener from window object for the API navigation event.
         */
        unregisterNavigationEvents() {
            this.navEventsRegistered = false;
            window.removeEventListener(EventTypes.Navigation.apiNavigate, this.navigationHandler);
        }
        /**
         * Handler for the API navigation event.
         *
         * Note, when the current type is set to `operation` then the `operationId` is
         * set instead of `domainId`, which is set to the parent endpoint id.
         */
        navigationHandler(e) {
            const { domainId, domainType, parentId, passive } = e.detail;
            if (passive === true) {
                return;
            }
            this.domainType = domainType;
            if (domainType === 'operation') {
                this.operationId = domainId;
                this.domainId = parentId;
            }
            else {
                this.operationId = undefined;
                this.domainId = domainId;
            }
            this.processGraph();
        }
        async processGraph() {
            this.schemaMimeType = undefined;
            await this.queryDocumentMeta();
            const { documentMeta } = this;
            if (!documentMeta) {
                this.requestUpdate();
                return;
            }
            if (documentMeta.isApi) {
                await this.queryApiSummary();
                this.processApiSpecSelection();
                return;
            }
            if (documentMeta.isLibrary) {
                this.processLibrarySelection();
                return;
            }
            const { isFragment, types } = documentMeta;
            if (isFragment) {
                let type;
                if (types.includes(AmfNamespace.aml.vocabularies.security.SecuritySchemeFragment)) {
                    type = 'security';
                }
                else if (types.includes(AmfNamespace.aml.vocabularies.apiContract.UserDocumentationFragment)) {
                    type = 'documentation';
                }
                else if (types.includes(AmfNamespace.aml.vocabularies.shapes.DataTypeFragment)) {
                    type = 'schema';
                }
                this.processFragment(type);
                return;
            }
            //
            // partial models
            //
            if (types.includes(AmfNamespace.aml.vocabularies.apiContract.EndPoint)) {
                this.processEndpointPartial();
                return;
            }
            let type;
            if (types.includes(AmfNamespace.aml.vocabularies.core.CreativeWork)) {
                type = 'documentation';
            }
            else if (types.includes(AmfNamespace.aml.vocabularies.security.SecurityScheme)) {
                type = 'security';
            }
            else if (types.includes(AmfNamespace.w3.shacl.Shape)) {
                type = 'schema';
            }
            this.processPartial(type);
        }
        /**
         * Reads the currently loaded document meta data from the store.
         */
        async queryDocumentMeta() {
            this.documentMetaValue = undefined;
            try {
                const info = await Events.Api.documentMeta(this);
                this.documentMetaValue = info;
            }
            catch (e) {
                const ex = e;
                Events.Telemetry.exception(this, ex.message, false);
                Events.Reporting.error(this, ex, `Unable to query for the document meta data: ${ex.message}`, this.localName);
            }
        }
        /**
         * Reads the API summary.
         * Called only when the currently loaded document is an API.
         */
        async queryApiSummary() {
            try {
                const info = await Events.Api.summary(this);
                this.apiSummaryValue = info;
            }
            catch (e) {
                this.apiSummaryValue = undefined;
                const ex = e;
                Events.Telemetry.exception(this, ex.message, false);
                Events.Reporting.error(this, ex, `Unable to query for the API summary data: ${ex.message}`, this.localName);
            }
        }
        /**
         * Processes selection for the web API data model. It ignores the input if
         * `domainId` or `domainType` is not set.
         */
        processApiSpecSelection() {
            const { domainId, tryItPanel } = this;
            let { domainType } = this;
            if (!domainId || !domainType) {
                // Not all required properties were set.
                return;
            }
            if (domainType === 'operation' && tryItPanel) {
                domainType = 'resource';
            }
            this.renderedViewValue = domainType;
            this.requestUpdate();
        }
        /**
         * Processes selection for a library data model. It ignores the input if
         * `domainId` or `domainType` is not set.
         */
        processLibrarySelection() {
            const { domainId, domainType } = this;
            if (!domainId || !domainType) {
                // Not all required properties were set.
                return;
            }
            this.renderedViewValue = domainType;
            this.requestUpdate();
        }
        /**
         * Processes fragment model and sets current selection and the model.
         *
         * @param domainType The selected domain type.
         */
        processFragment(domainType) {
            this.domainIdValue = this.documentMeta?.encodesId;
            this.renderedViewValue = domainType;
            this.requestUpdate();
        }
        /**
         * Sets the partial model to be rendered.
         *
         * @param domainType The domain type representing the partial model.
         */
        processPartial(domainType) {
            this.renderedViewValue = domainType;
            this.requestUpdate();
        }
        /**
         * Processes endpoint data from partial model definition.
         * It sets models that are used by the docs.
         *
         * If `selected` or `selectedType` is not set then it automatically selects
         */
        processEndpointPartial() {
            const { tryItPanel } = this;
            let { domainType } = this;
            if (!domainType || tryItPanel) {
                domainType = 'resource';
            }
            if (!['operation', 'resource'].includes(domainType)) {
                domainType = 'resource';
            }
            this.renderedViewValue = domainType;
            this.requestUpdate();
        }
        serversCountHandler(e) {
            this.serversCount = e.detail.value;
        }
        serverChangeHandler(e) {
            this.serverValue = e.detail.value;
            this.serverType = e.detail.type;
        }
        mediaTypeSelectHandler(e) {
            const node = e.target;
            const { value } = node;
            this.schemaMimeType = value;
        }
        render() {
            return html ` ${this.serverSelectorTemplate()} ${this.modelTemplate()}`;
        }
        /**
         * @returns The template for the server selector.
         */
        serverSelectorTemplate() {
            if (this.noServerSelector) {
                return '';
            }
            const { serverType, serverValue, allowCustomBaseUri, renderSelector, domainId, domainType } = this;
            const id = domainType === 'operation' ? this.operationId : domainId;
            return html ` <api-server-picker
      class="server-selector"
      .domainId="${id}"
      .domainType="${domainType}"
      .value="${serverValue}"
      .type="${serverType}"
      ?hidden="${!renderSelector}"
      ?custom="${allowCustomBaseUri}"
      auto
      @serverscountchanged="${this.serversCountHandler}"
      @apiserverchanged="${this.serverChangeHandler}"
    >
      <slot name="custom-base-uri" slot="custom-base-uri"></slot>
    </api-server-picker>`;
        }
        /**
         * @returns The template for the server selector.
         */
        modelTemplate() {
            switch (this.renderedViewValue) {
                case 'summary':
                    return this.summaryTemplate();
                case 'security':
                    return this.securityTemplate();
                case 'documentation':
                    return this.documentationTemplate();
                case 'schema':
                    return this.schemaTemplate();
                case 'resource':
                case 'operation':
                    return this.resourceTemplate();
                default:
                    return '';
            }
        }
        /**
         * @returns The template for the API summary page.
         */
        summaryTemplate() {
            const { baseUri } = this;
            return html ` <api-summary .baseUri="${baseUri}"></api-summary>`;
        }
        /**
         * @returns The template for the API security definition page.
         */
        securityTemplate() {
            const { domainId } = this;
            return html `<api-security-document .domainId="${domainId}" settingsOpened></api-security-document>`;
        }
        /**
         * @returns The template for the RAML's documentation page.
         */
        documentationTemplate() {
            const { domainId } = this;
            return html `<api-documentation-document .domainId="${domainId}"></api-documentation-document>`;
        }
        /**
         * @returns The template for the API schema page.
         */
        schemaTemplate() {
            const { schemaMime, domainId } = this;
            return html ` ${this.schemaMediaSelectorTemplate()}
      <api-schema-document .domainId="${domainId}" .mimeType="${schemaMime}" forceExamples></api-schema-document>`;
        }
        /**
         * @returns The template for the API endpoint page.
         */
        resourceTemplate() {
            const { domainId, operationId, isAsync } = this;
            return html `<api-resource-document
      .domainId="${domainId}"
      .operationId="${operationId}"
      .redirectUri="${this.redirectUri}"
      .serverType="${this.serverType}"
      .serverValue="${this.serverValue}"
      .baseUri="${this.apiBaseUri}"
      ?tryItButton="${this.tryItButton}"
      ?tryItPanel="${this.tryItPanel}"
      ?httpUrlEditor="${this.httpUrlEditor}"
      httpNoServerSelector
      ?asyncApi="${isAsync}"
    ></api-resource-document>`;
        }
        /**
         * This is a part of schema rendering.
         * When the current API defines the media types then this shows the selector
         * to render examples with a specific mime.
         */
        schemaMediaSelectorTemplate() {
            const { documentMeta } = this;
            // only APIs have top level media types (?)
            const summary = this.apiSummaryValue;
            if (!summary || !documentMeta || !documentMeta.isApi) {
                return '';
            }
            const { accepts = [] } = summary;
            if (accepts.length < 2) {
                // if there's a single mime then we render the one we have. No selector needed.
                return '';
            }
            const mimeType = this.schemaMimeType || accepts[0];
            return html `
      <div class="media-type-selector">
        <span id="schema-mime">Schema content type</span>
        ${accepts.map((item) => html `
            <label class="label-large">
              <ui-radio
                class="schema-toggle"
                name="schemaMime"
                value="${item}"
                .checked="${item === mimeType}"
                @change="${this.mediaTypeSelectHandler}"
              ></ui-radio>
              ${item}
            </label>
          `)}
      </div>
    `;
        }
    };
})();
/**
 * A main documentation view for an AMF model representing a sync or an async API.
 *
 * This element works with the [AMF](https://github.com/mulesoft/amf) data model.
 */
export default ApiDocumentation;
//# sourceMappingURL=ApiDocumentation.element.js.map