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 _GxIdeLaunchpad_componentLocale;
import { Host, h } from "@stencil/core";
import { Locale } from "../../../common/locale";
const CSS_BUNDLES = [
    "resets/box-sizing",
    "components/tab",
    "utils/form--full",
    "utils/layout",
    "utils/typography",
    "utils/spacing",
    "chameleon/scrollbar"
];
const MAIN_SECTION_CLASSES = "main";
const WEB_APPS_TAB_SELECTOR = "web-apps";
const NATIVE_APPS_TAB_SELECTOR = "native-apps";
const APIS_TAB_SELECTOR = "apis";
// Temporary WA (Read WA in launchpad.scss)
const TAB_SLOT_SPACING_BODY_SELECTOR = "tab-slot-spacing-body";
export class GxIdeLaunchpad {
    constructor() {
        _GxIdeLaunchpad_componentLocale.set(this, void 0);
        this.data = undefined;
        this.isStandalone = true;
        this.sections = [];
        this.tabModel = [];
    }
    watchDataHandler(newValue) {
        if (newValue !== undefined) {
            this.organizeData();
        }
    }
    async componentWillLoad() {
        try {
            __classPrivateFieldSet(this, _GxIdeLaunchpad_componentLocale, await Locale.getComponentStrings(this.el), "f");
        }
        catch (error) {
            console.error("Error loading locale:", error);
            __classPrivateFieldSet(this, _GxIdeLaunchpad_componentLocale, {
                tabs: {
                    webApps: "WEB APPS",
                    nativeApps: "NATIVE APPS",
                    apis: "APIS"
                }
            }, "f");
        }
        if (this.data) {
            this.organizeData();
        }
    }
    componentDidLoad() { }
    /**
     * Organizes received data and builds tab model
     */
    organizeData() {
        if (this.data) {
            try {
                const parsedData = typeof this.data === "string" ? JSON.parse(this.data) : this.data;
                this.sections = parsedData.sections || [];
                this.buildTabModel();
            }
            catch (error) {
                console.error("Error parsing launchpad data:", error);
                this.sections = [];
                this.tabModel = [];
            }
        }
    }
    /**
     * Builds tab model based on sections
     */
    buildTabModel() {
        if (this.sections && this.sections.length > 0) {
            this.tabModel = this.sections.map(section => ({
                id: section.id,
                name: this.getLocalizedTabName(section.id)
            }));
        }
    }
    /**
     * Gets localized tab name based on section ID
     */
    getLocalizedTabName(sectionId) {
        var _a;
        const tabNames = ((_a = __classPrivateFieldGet(this, _GxIdeLaunchpad_componentLocale, "f")) === null || _a === void 0 ? void 0 : _a.tabs) || {};
        switch (sectionId) {
            case "web-apps":
                return tabNames.webApps || "WEB APPS";
            case "native-apps":
                return tabNames.nativeApps || "NATIVE APPS";
            case "apis":
                return tabNames.apis || "APIS";
            default:
                return sectionId.toUpperCase().replace(/-/g, " ");
        }
    }
    /**
     * Handles object selection from subcomponents
     */
    handleObjectSelection(event) {
        let key = event.detail.key;
        // Convert string format "type|id" to object format
        if (typeof key === "string" && key.includes("|")) {
            const parts = key.split("|");
            if (parts.length === 2) {
                key = {
                    type: parts[0],
                    id: parts[1]
                };
            }
        }
        this.objectSelected.emit({ key });
    }
    /**
     * Handles copy to clipboard from subcomponents
     */
    handleCopyToClipboard(event) {
        this.copyToClipboard.emit({ url: event.detail.url });
    }
    /**
     * Handles open app store from subcomponents
     */
    handleOpenAppStore(event) {
        this.openOnTheAppStore.emit({ url: event.detail.url });
    }
    render() {
        var _a, _b, _c;
        if (!this.data || !this.sections || this.sections.length === 0) {
            return null;
        }
        // TODO: Revisit re-enabling keyboard shortcuts 1, 2, 3 for switching launchpad tabs (Web Apps, Native Apps, APIs)
        return (h(Host, null, h("ch-theme", { model: CSS_BUNDLES }), h("ch-tab-render", { class: {
                scrollable: true,
                tab: true,
                [MAIN_SECTION_CLASSES]: true
            }, tabListPosition: "block-start", model: this.tabModel, selectedId: WEB_APPS_TAB_SELECTOR, overflow: "auto", contain: "size" }, h("div", { slot: WEB_APPS_TAB_SELECTOR, class: { "web-apps": true, [TAB_SLOT_SPACING_BODY_SELECTOR]: true }, part: "tab-button-web-apps" }, h("gx-ide-launchpad-web-apps", Object.assign({ objects: ((_a = this.sections.find(s => s.id === "web-apps")) === null || _a === void 0 ? void 0 : _a.objects) || [] }, {
            onObjectSelected: (event) => this.handleObjectSelection(event)
        }, {
            onCopyToClipboard: (event) => this.handleCopyToClipboard(event)
        }))), h("div", { slot: NATIVE_APPS_TAB_SELECTOR, class: {
                "native-apps": true,
                [TAB_SLOT_SPACING_BODY_SELECTOR]: true
            }, part: "tab-button-native-apps" }, h("gx-ide-launchpad-native-apps", Object.assign({ objects: ((_b = this.sections.find(s => s.id === "native-apps")) === null || _b === void 0 ? void 0 : _b.objects) || [] }, {
            onObjectSelected: (event) => this.handleObjectSelection(event)
        }, {
            onCopyToClipboard: (event) => this.handleCopyToClipboard(event)
        }, {
            onOpenOnTheAppStore: (event) => this.handleOpenAppStore(event)
        }))), h("div", { slot: APIS_TAB_SELECTOR, class: { apis: true, [TAB_SLOT_SPACING_BODY_SELECTOR]: true }, part: "tab-button-apis" }, h("gx-ide-launchpad-apis", Object.assign({ apis: ((_c = this.sections.find(s => s.id === "apis")) === null || _c === void 0 ? void 0 : _c.apis) || [] }, {
            onObjectSelected: (event) => this.handleObjectSelection(event)
        }, {
            onCopyToClipboard: (event) => this.handleCopyToClipboard(event)
        }))))));
    }
    static get is() { return "gx-ide-launchpad"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["launchpad.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["launchpad.css"]
        };
    }
    static get assetsDirs() { return ["gx-ide-assets/launchpad"]; }
    static get properties() {
        return {
            "data": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string | undefined",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "JSON data containing section structure"
                },
                "attribute": "data",
                "reflect": false,
                "defaultValue": "undefined"
            },
            "isStandalone": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Determines if the component runs in standalone mode"
                },
                "attribute": "is-standalone",
                "reflect": false,
                "defaultValue": "true"
            }
        };
    }
    static get states() {
        return {
            "sections": {},
            "tabModel": {}
        };
    }
    static get events() {
        return [{
                "method": "objectSelected",
                "name": "objectSelected",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "Event emitted when an object is selected for execution"
                },
                "complexType": {
                    "original": "{\n    key: { type: string; id: string } | string;\n  }",
                    "resolved": "{ key: string | { type: string; id: string; }; }",
                    "references": {}
                }
            }, {
                "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": {}
                }
            }, {
                "method": "openOnTheAppStore",
                "name": "openOnTheAppStore",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "Event emitted when opening app store"
                },
                "complexType": {
                    "original": "{ url: string }",
                    "resolved": "{ url: string; }",
                    "references": {}
                }
            }];
    }
    static get elementRef() { return "el"; }
    static get watchers() {
        return [{
                "propName": "data",
                "methodName": "watchDataHandler"
            }];
    }
}
_GxIdeLaunchpad_componentLocale = new WeakMap();
//# sourceMappingURL=launchpad.js.map
