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 _GxIdeLaunchpadNativeApps_instances, _GxIdeLaunchpadNativeApps_componentLocale, _GxIdeLaunchpadNativeApps_ACCORDION_MODEL, _GxIdeLaunchpadNativeApps_timeoutIds, _GxIdeLaunchpadNativeApps_getQRFillColor, _GxIdeLaunchpadNativeApps_getQRBackgroundColor, _GxIdeLaunchpadNativeApps_getCopyIcon, _GxIdeLaunchpadNativeApps_copyToClipboardFunc, _GxIdeLaunchpadNativeApps_openAppStoreFunc, _GxIdeLaunchpadNativeApps_handleQRClick, _GxIdeLaunchpadNativeApps_handleCloseQRDialog, _GxIdeLaunchpadNativeApps_handleObjectClick, _GxIdeLaunchpadNativeApps_renderPlatformSection;
import { h, getAssetPath } from "@stencil/core";
import { getIconPath } from "@genexus/mercury";
import { Locale } from "../../../common/locale";
const IOS_ID = "ios";
const ANDROID_ID = "android";
const APP_STORE_BADGE = getAssetPath("./gx-ide-assets/launchpad-native-apps/images/app-store-badge.svg");
const ANDROID_LOGO = getAssetPath("./gx-ide-assets/launchpad-native-apps/images/android-logo.svg");
const MAC_LOGO = getAssetPath("./gx-ide-assets/launchpad-native-apps/images/mac-logo.svg");
const CSS_BUNDLES = [
    "resets/box-sizing",
    "components/accordion",
    "components/button",
    "components/dialog",
    "components/icon",
    "utils/elevation",
    "utils/layout",
    "utils/spacing",
    "utils/typography"
];
const QR_ICON = getIconPath({
    category: "system",
    name: "qr-code",
    colorType: "interactive"
});
export class GxIdeLaunchpadNativeApps {
    constructor() {
        _GxIdeLaunchpadNativeApps_instances.add(this);
        _GxIdeLaunchpadNativeApps_componentLocale.set(this, void 0);
        _GxIdeLaunchpadNativeApps_ACCORDION_MODEL.set(this, []);
        _GxIdeLaunchpadNativeApps_timeoutIds.set(this, new Set());
        this.objects = [];
        this.filterValue = "";
        this.order = {
            orderCriteria: null,
            ascending: null
        };
        this.page = 1;
        this.perPage = 10;
        this.onObjectSelected = undefined;
        this.showCopiedMessage = {};
        this.showQRDialog = false;
        this.selectedObjectForQR = null;
    }
    async componentWillLoad() {
        try {
            __classPrivateFieldSet(this, _GxIdeLaunchpadNativeApps_componentLocale, await Locale.getComponentStrings(this.el), "f");
        }
        catch (error) {
            console.error("Error loading locale:", error);
            __classPrivateFieldSet(this, _GxIdeLaunchpadNativeApps_componentLocale, {}, "f");
        }
        __classPrivateFieldSet(this, _GxIdeLaunchpadNativeApps_ACCORDION_MODEL, [
            {
                id: IOS_ID,
                caption: "iOS",
                expanded: true
            },
            {
                id: ANDROID_ID,
                caption: "Android",
                expanded: true
            }
        ], "f");
    }
    /**
     * Cleanup method to prevent memory leaks
     */
    disconnectedCallback() {
        if (__classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_timeoutIds, "f")) {
            __classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_timeoutIds, "f").forEach(timeoutId => {
                if (timeoutId) {
                    clearTimeout(timeoutId);
                }
            });
            __classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_timeoutIds, "f").clear();
        }
    }
    render() {
        var _a;
        if (!this.objects || this.objects.length === 0) {
            h("div", { class: "no-data" }, h("p", { class: "body-regular-s" }, ((_a = __classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_componentLocale, "f")) === null || _a === void 0 ? void 0 : _a.noData) ||
                "No native applications data available"));
        }
        return [
            h("ch-theme", { model: CSS_BUNDLES }),
            h("div", { class: "main" }, h("ch-accordion-render", { class: "accordion-filled-header elevation-1 native-apps-accordion", model: __classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_ACCORDION_MODEL, "f") }, h("div", { slot: IOS_ID, class: "accordion-content spacing-body" }, __classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_instances, "m", _GxIdeLaunchpadNativeApps_renderPlatformSection).call(this, IOS_ID)), h("div", { slot: ANDROID_ID, class: "accordion-content spacing-body" }, __classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_instances, "m", _GxIdeLaunchpadNativeApps_renderPlatformSection).call(this, ANDROID_ID)))),
            h("ch-dialog", { class: "dialog", show: this.showQRDialog, "show-header": true, closable: true, "close-button-accessible-name": "Close QR code", onDialogClosed: () => __classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_instances, "m", _GxIdeLaunchpadNativeApps_handleCloseQRDialog).call(this) }, this.selectedObjectForQR && (h("div", { class: "qr-container" }, h("ch-qr", { value: this.selectedObjectForQR.url || "", size: 200, "error-correction-level": "Low", class: "qr-code", fill: __classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_instances, "m", _GxIdeLaunchpadNativeApps_getQRFillColor).call(this), background: __classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_instances, "m", _GxIdeLaunchpadNativeApps_getQRBackgroundColor).call(this) }))))
        ];
    }
    static get is() { return "gx-ide-launchpad-native-apps"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["launchpad-native-apps.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["launchpad-native-apps.css"]
        };
    }
    static get assetsDirs() { return ["gx-ide-assets/launchpad-native-apps"]; }
    static get properties() {
        return {
            "objects": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "PlatformSection[]",
                    "resolved": "PlatformSection[]",
                    "references": {
                        "PlatformSection": {
                            "location": "global",
                            "id": "global::PlatformSection"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Array of platform sections (ios, android)"
                },
                "defaultValue": "[]"
            },
            "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 states() {
        return {
            "filterValue": {},
            "order": {},
            "page": {},
            "perPage": {},
            "showCopiedMessage": {},
            "showQRDialog": {},
            "selectedObjectForQR": {}
        };
    }
    static get events() {
        return [{
                "method": "copyToClipboard",
                "name": "copyToClipboard",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "Event emitted when copying to clipboard - like the original version"
                },
                "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 - like the original version"
                },
                "complexType": {
                    "original": "{ url: string }",
                    "resolved": "{ url: string; }",
                    "references": {}
                }
            }];
    }
    static get elementRef() { return "el"; }
}
_GxIdeLaunchpadNativeApps_componentLocale = new WeakMap(), _GxIdeLaunchpadNativeApps_ACCORDION_MODEL = new WeakMap(), _GxIdeLaunchpadNativeApps_timeoutIds = new WeakMap(), _GxIdeLaunchpadNativeApps_instances = new WeakSet(), _GxIdeLaunchpadNativeApps_getQRFillColor = function _GxIdeLaunchpadNativeApps_getQRFillColor() {
    const computedStyle = getComputedStyle(document.documentElement);
    return (computedStyle.getPropertyValue("--color-text-neutral-default").trim() ||
        computedStyle.getPropertyValue("--color-neutral-400").trim() ||
        "#49566d");
}, _GxIdeLaunchpadNativeApps_getQRBackgroundColor = function _GxIdeLaunchpadNativeApps_getQRBackgroundColor() {
    const computedStyle = getComputedStyle(document.documentElement);
    return (computedStyle.getPropertyValue("--color-neutral-1600").trim() || "#ffffff");
}, _GxIdeLaunchpadNativeApps_getCopyIcon = function _GxIdeLaunchpadNativeApps_getCopyIcon() {
    return getIconPath({
        category: "system",
        name: "copy",
        colorType: "primary"
    });
}, _GxIdeLaunchpadNativeApps_copyToClipboardFunc = function _GxIdeLaunchpadNativeApps_copyToClipboardFunc(object) {
    this.copyToClipboard.emit({
        url: object.url
    });
    if (object.url) {
        navigator.clipboard
            .writeText(object.url)
            .then(() => {
            const objectKey = `${object.name}-${object.url}`;
            this.showCopiedMessage = Object.assign(Object.assign({}, this.showCopiedMessage), { [objectKey]: true });
            const timeoutId = window.setTimeout(() => {
                this.showCopiedMessage = Object.assign(Object.assign({}, this.showCopiedMessage), { [objectKey]: false });
                __classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_timeoutIds, "f").delete(timeoutId);
            }, 2000);
            __classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_timeoutIds, "f").add(timeoutId);
        })
            .catch(err => {
            console.error("Failed to copy text: ", err);
        });
    }
}, _GxIdeLaunchpadNativeApps_openAppStoreFunc = function _GxIdeLaunchpadNativeApps_openAppStoreFunc(object) {
    this.openOnTheAppStore.emit({
        url: object.url
    });
    if (object.url) {
        window.open(object.url, "_blank");
    }
}, _GxIdeLaunchpadNativeApps_handleQRClick = function _GxIdeLaunchpadNativeApps_handleQRClick(object) {
    this.selectedObjectForQR = object;
    this.showQRDialog = true;
}, _GxIdeLaunchpadNativeApps_handleCloseQRDialog = function _GxIdeLaunchpadNativeApps_handleCloseQRDialog() {
    this.showQRDialog = false;
    this.selectedObjectForQR = null;
}, _GxIdeLaunchpadNativeApps_handleObjectClick = function _GxIdeLaunchpadNativeApps_handleObjectClick(object) {
    if (object.key && this.onObjectSelected) {
        // Send the full key object as string in format "type|id"
        const keyString = `${object.key.type}|${object.key.id}`;
        this.onObjectSelected({ detail: { key: keyString } });
    }
}, _GxIdeLaunchpadNativeApps_renderPlatformSection = function _GxIdeLaunchpadNativeApps_renderPlatformSection(platformType) {
    var _a, _b;
    const platformIcon = platformType === IOS_ID ? (h("img", { src: MAC_LOGO, alt: "Apple iOS Logo" })) : (h("img", { src: ANDROID_LOGO, alt: "Android Logo" }));
    const platformSection = this.objects.find(obj => obj.type === platformType);
    if (!platformSection || platformSection.objects.length === 0) {
        return (h("div", { class: "no-results" }, h("p", { class: "body-regular-s" }, ((_b = (_a = __classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_componentLocale, "f")) === null || _a === void 0 ? void 0 : _a.noPlatformApps) === null || _b === void 0 ? void 0 : _b.replace("{platformType}", platformType)) || `No ${platformType} applications available`)));
    }
    return (h("div", { class: "platform-grid" }, platformSection.objects.map((object, index) => {
        var _a, _b, _c;
        return (h("div", { key: index, class: "object-card elevation-1", tabindex: "0", onClick: () => __classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_instances, "m", _GxIdeLaunchpadNativeApps_handleObjectClick).call(this, object) }, h("div", { class: "card-content" }, h("div", { class: "info-section" }, h("div", { class: "app-info" }, h("h1", { class: "name body-semi-bold-s" }, object.name), object.description && (h("p", { class: "description body-regular-xs" }, object.description))))), h("div", { class: "card-actions" }, object.url && (h("div", { class: "platform-section" }, object["app-store-badge"] ? (h("img", { src: APP_STORE_BADGE, alt: "Download on the App Store", class: "app__apple-store", onClick: () => __classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_instances, "m", _GxIdeLaunchpadNativeApps_openAppStoreFunc).call(this, object) })) : (platformIcon), h("button", { class: "button-secondary button-icon-and-text", onClick: () => __classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_instances, "m", _GxIdeLaunchpadNativeApps_handleQRClick).call(this, object), "aria-label": "Show QR Code" }, h("ch-image", { class: "icon-m", src: QR_ICON, type: "mask" }), ((_a = __classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_componentLocale, "f")) === null || _a === void 0 ? void 0 : _a.showQR) || "Show QR"))), h("button", { class: "button-tertiary button-icon-and-text copy-button", onClick: () => __classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_instances, "m", _GxIdeLaunchpadNativeApps_copyToClipboardFunc).call(this, object), "aria-label": "Copy to clipboard" }, h("ch-image", { class: "icon-m", src: __classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_instances, "m", _GxIdeLaunchpadNativeApps_getCopyIcon).call(this) }), this.showCopiedMessage[`${object.name}-${object.url}`]
            ? ((_b = __classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_componentLocale, "f")) === null || _b === void 0 ? void 0 : _b.copied) || "Copied!"
            : ((_c = __classPrivateFieldGet(this, _GxIdeLaunchpadNativeApps_componentLocale, "f")) === null || _c === void 0 ? void 0 : _c.copy) || "Copy"))));
    }), 
    // WA: Prevent card take full width if there is only one card
    platformSection.objects.length === 1 && h("div", null)));
};
//# sourceMappingURL=launchpad-native-apps.js.map
