import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
import { L as Locale } from './locale.js';
import { d as defineCustomElement$1 } from './launchpad-api.js';

const launchpadApisCss = ":host{display:block;block-size:100%;overflow:auto;background-color:var(--ch-color-surface-primary);color:var(--ch-color-text-primary)}.main{overflow:auto;display:block}.apis-container{padding:24px;display:flex;flex-direction:column;gap:var(--spacing-gap-xl);max-width:100%}.api-item{background:var(--ch-color-surface-secondary);border:1px solid var(--color-border-neutral-default);border-radius:0;overflow:hidden;transition:all var(--timing-fast) ease;width:100%;max-width:100%;display:flex;flex-direction:column;min-height:64px}.api-item:hover{box-shadow:var(--color-accent-surface-elevation-2);transform:translateY(-2px);border-color:var(--color-border-primary-hover)}.api-header{padding:16px;background:transparent;border-bottom:1px solid var(--color-border-neutral-default);flex-shrink:0}.api-header .api-name{margin:0;color:var(--color-text-neutral-default);word-break:break-all;overflow-wrap:break-word}.api-content{overflow:hidden}.no-apis,.no-data{color:var(--color-text-neutral-disabled);font-style:italic;text-align:center;padding:16px}.no-apis p,.no-data p{font-size:var(--font-size-body-m);font-weight:var(--font-style-semi-bold);line-height:var(--line-height-spacious)}";

var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
    if (kind === "m")
        throw new TypeError("Private method is not writable");
    if (kind === "a" && !f)
        throw new TypeError("Private accessor was defined without a setter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
        throw new TypeError("Cannot write private member to an object whose class did not declare it");
    return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
    if (kind === "a" && !f)
        throw new TypeError("Private accessor was defined without a getter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
        throw new TypeError("Cannot read private member from an object whose class did not declare it");
    return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _GxIdeLaunchpadApis_componentLocale, _GxIdeLaunchpadApis_ACCORDION_MODEL;
const CSS_BUNDLES = [
    "resets/box-sizing",
    "components/accordion",
    "utils/elevation",
    "utils/layout",
    "utils/typography",
    "utils/spacing"
];
const GxIdeLaunchpadApis = /*@__PURE__*/ proxyCustomElement(class GxIdeLaunchpadApis extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.__attachShadow();
        this.copyToClipboard = createEvent(this, "copyToClipboard", 7);
        _GxIdeLaunchpadApis_componentLocale.set(this, void 0);
        _GxIdeLaunchpadApis_ACCORDION_MODEL.set(this, []);
        this.apis = undefined;
        this.onObjectSelected = undefined;
    }
    async componentWillLoad() {
        try {
            __classPrivateFieldSet(this, _GxIdeLaunchpadApis_componentLocale, await Locale.getComponentStrings(this.element), "f");
        }
        catch (error) {
            console.error("Error loading locale:", error);
            __classPrivateFieldSet(this, _GxIdeLaunchpadApis_componentLocale, {}, "f");
        }
        this.initializeAccordionModel();
    }
    /**
     * Initialize accordion model with dynamic sections for each API
     */
    initializeAccordionModel() {
        if (!this.apis || !Array.isArray(this.apis)) {
            __classPrivateFieldSet(this, _GxIdeLaunchpadApis_ACCORDION_MODEL, [], "f");
            return;
        }
        __classPrivateFieldSet(this, _GxIdeLaunchpadApis_ACCORDION_MODEL, this.apis
            .map((api, index) => {
            let url;
            if (typeof api === "string") {
                url = api;
            }
            else if (api && typeof api === "object" && api.url) {
                url = api.url.toString();
            }
            else {
                return null;
            }
            const lastSlash = url.lastIndexOf("/");
            const name = url.substring(lastSlash + 1, url.length).toUpperCase();
            return {
                id: `api-${index}`,
                caption: name,
                expanded: true
            };
        })
            .filter(Boolean), "f");
    }
    renderApis() {
        if (!this.apis || !Array.isArray(this.apis)) {
            return null;
        }
        return this.apis
            .map((api, index) => {
            let apiData;
            if (typeof api === "string") {
                apiData = { url: api };
            }
            else if (api && typeof api === "object" && api.url) {
                apiData = api;
            }
            else {
                return null;
            }
            return (h("div", { key: `api-${index}`, slot: `api-${index}`, class: "api-content spacing-body" }, h("gx-ide-launchpad-api", { data: apiData, onObjectSelected: (event) => this.handleObjectSelection(event), onCopyToClipboard: (event) => this.handleCopyToClipboard(event) })));
        })
            .filter(Boolean);
    }
    /**
     * Handles object selection from subcomponents
     */
    handleObjectSelection(event) {
        if (this.onObjectSelected) {
            this.onObjectSelected(event);
        }
    }
    /**
     * Handles copy to clipboard from subcomponents
     */
    handleCopyToClipboard(event) {
        this.copyToClipboard.emit({ url: event.detail.url });
    }
    render() {
        var _a;
        if (!this.apis || this.apis.length === 0) {
            return (h(Host, null, h("ch-theme", { model: CSS_BUNDLES }), h("div", { class: "no-data" }, h("p", { class: "body-regular-s" }, ((_a = __classPrivateFieldGet(this, _GxIdeLaunchpadApis_componentLocale, "f")) === null || _a === void 0 ? void 0 : _a.noApis) || "No APIs available"))));
        }
        return (h(Host, null, h("ch-theme", { model: CSS_BUNDLES }), h("div", { class: "main" }, h("ch-accordion-render", { class: "accordion-filled-header elevation-2 apis-accordion", model: __classPrivateFieldGet(this, _GxIdeLaunchpadApis_ACCORDION_MODEL, "f") }, this.renderApis()))));
    }
    static get assetsDirs() { return ["gx-ide-assets/launchpad-apis"]; }
    get element() { return this; }
    static get style() { return launchpadApisCss; }
}, [1, "gx-ide-launchpad-apis", {
        "apis": [16],
        "onObjectSelected": [16]
    }]);
_GxIdeLaunchpadApis_componentLocale = new WeakMap(), _GxIdeLaunchpadApis_ACCORDION_MODEL = new WeakMap();
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["gx-ide-launchpad-apis", "gx-ide-launchpad-api"];
    components.forEach(tagName => { switch (tagName) {
        case "gx-ide-launchpad-apis":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, GxIdeLaunchpadApis);
            }
            break;
        case "gx-ide-launchpad-api":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}

export { GxIdeLaunchpadApis as G, defineCustomElement as d };

//# sourceMappingURL=launchpad-apis.js.map