var __classPrivateFieldSet = (this && this.__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 = (this && this.__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;
import { Host, h } from "@stencil/core";
import { Locale } from "../../../common/locale";
const CSS_BUNDLES = [
    "resets/box-sizing",
    "components/accordion",
    "utils/elevation",
    "utils/layout",
    "utils/typography",
    "utils/spacing"
];
export class GxIdeLaunchpadApis {
    constructor() {
        _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 is() { return "gx-ide-launchpad-apis"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["launchpad-apis.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["launchpad-apis.css"]
        };
    }
    static get assetsDirs() { return ["gx-ide-assets/launchpad-apis"]; }
    static get properties() {
        return {
            "apis": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "Array<any>",
                    "resolved": "any[]",
                    "references": {
                        "Array": {
                            "location": "global",
                            "id": "global::Array"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                }
            },
            "onObjectSelected": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "(event: any) => void",
                    "resolved": "(event: any) => void",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Callback function for object selection (passed from parent)"
                }
            }
        };
    }
    static get events() {
        return [{
                "method": "copyToClipboard",
                "name": "copyToClipboard",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "Event emitted when copying to clipboard"
                },
                "complexType": {
                    "original": "{ url: string }",
                    "resolved": "{ url: string; }",
                    "references": {}
                }
            }];
    }
    static get elementRef() { return "element"; }
}
_GxIdeLaunchpadApis_componentLocale = new WeakMap(), _GxIdeLaunchpadApis_ACCORDION_MODEL = new WeakMap();
//# sourceMappingURL=launchpad-apis.js.map
