import { getAssetPath, proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
import { g as getIconPath } from './mer-animated-dots.js';
import 'lit';
import 'lit/directives/when.js';
import 'lit/directives/if-defined.js';
import { L as Locale } from './locale.js';

const launchpadNativeAppsCss = ".object-card{border:none;border-radius:4px;padding:12px;display:flex;gap:var(--spacing-gap-l);flex-direction:column;flex-shrink:0;text-align:left}.platform-grid{display:grid;grid-template-columns:repeat(auto-fit, minmax(var(--card-min-inline-size, 300px), var(--card-max-inline-size, 1fr)));gap:var(--spacing-gap-l);align-items:stretch}button.button-secondary{border-color:var(--color-border-neutral-default)}:host{display:block;block-size:100%;overflow:auto}.main{overflow:auto;display:block}ch-accordion-render{inline-size:100%;block-size:100%}.native-apps-accordion{inline-size:100%;block-size:100%}.platform-section{display:flex;align-items:center;gap:var(--spacing-gap-l)}.app__apple-store{height:32px;cursor:pointer;transition:opacity var(--timing-fast) ease}.app__apple-store:hover{opacity:0.8}.platform-grid{--card-min-inline-size:360px}.card-content{display:flex;gap:var(--spacing-gap-xl);flex:1;width:100%}.card-content:focus{outline:none}.info-section{flex:1;display:flex;flex-direction:column;justify-content:space-between;width:100%}.app-info{display:flex;flex-direction:column;gap:var(--spacing-gap-xs);flex:1}.name{color:var(--color-text-neutral-default)}.description{color:var(--color-text-neutral-disabled);margin:0;line-height:var(--line-height-relaxed)}.dialog{--ch-dialog-block-size:400px;--ch-dialog-inline-size:350px;--ch-dialog-min-block-size:400px;--ch-dialog-min-inline-size:350px}.qr-container{display:flex;align-items:center;justify-content:center}.card-actions{display:flex;justify-content:space-between;align-items:center;padding-top:12px;border-top:1px solid var(--color-border-neutral-default)}.no-data,.no-results{color:var(--color-text-neutral-disabled);font-style:italic;text-align:center;padding:16px}.no-data p,.no-results p{font-size:var(--font-size-body-m);font-weight:var(--font-style-semi-bold);line-height:var(--line-height-spacious)}@media (max-width: 768px){.platform-grid{justify-content:center}.card-content{flex-direction:column;gap:var(--spacing-gap-l)}.card-actions{flex-direction:column;gap:var(--spacing-gap-l);align-items:stretch}}@media (max-width: 480px){.main{padding:12px}.object-card{padding:12px}.platform-grid{gap:var(--spacing-gap-l);padding:12px}}.android:after{content:\"\";display:block}";

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 _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;
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"
});
const GxIdeLaunchpadNativeApps = /*@__PURE__*/ proxyCustomElement(class GxIdeLaunchpadNativeApps extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.__attachShadow();
        this.copyToClipboard = createEvent(this, "copyToClipboard", 7);
        this.openOnTheAppStore = createEvent(this, "openOnTheAppStore", 7);
        _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 assetsDirs() { return ["gx-ide-assets/launchpad-native-apps"]; }
    get el() { return this; }
    static get style() { return launchpadNativeAppsCss; }
}, [1, "gx-ide-launchpad-native-apps", {
        "objects": [16],
        "onObjectSelected": [16],
        "filterValue": [32],
        "order": [32],
        "page": [32],
        "perPage": [32],
        "showCopiedMessage": [32],
        "showQRDialog": [32],
        "selectedObjectForQR": [32]
    }]);
_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)));
};
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["gx-ide-launchpad-native-apps"];
    components.forEach(tagName => { switch (tagName) {
        case "gx-ide-launchpad-native-apps":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, GxIdeLaunchpadNativeApps);
            }
            break;
    } });
}

export { GxIdeLaunchpadNativeApps as G, defineCustomElement as d };

//# sourceMappingURL=launchpad-native-apps.js.map