import { getAssetPath, proxyCustomElement, HTMLElement, createEvent, h, Host } 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 launchpadWebAppsCss = ".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}.object-card:focus-visible{outline:none;border-color:var(--focus__outline-color)}.object-card:hover{cursor:pointer;border-color:var(--color-border-item-hover)}.object-card:active{border-color:var(--color-border-item-pressed)}:host{display:block;block-size:100%;overflow:auto}.main{overflow:auto;display:block}.input-filter{inline-size:33%;min-inline-size:300px}ch-accordion-render{inline-size:100%;block-size:100%}.accordion-content{inline-size:100%;overflow-x:auto;min-width:0}.web-apps-accordion{inline-size:100%;block-size:100%}.main-objects-grid{display:grid;grid-template-columns:repeat(auto-fit, minmax(267px, 1fr));gap:var(--spacing-gap-l);align-items:stretch}.object-card{inline-size:100%;border-width:1px;border-style:solid}.object-card.elevation-1{--elevation-border-color:var(\n    --color-accent-surface-elevation-1\n  )}.card-header{display:flex;justify-content:space-between;align-items:flex-start;flex-shrink:0}.card-header .left{display:flex;flex-direction:column;flex:1;gap:8px}.card-header .left .name{color:var(--color-text-neutral-default);font-weight:var(--font-style-regular)}.card-header .left .module{color:var(--ch-color-text-secondary);margin:0}.card-header .right .type-container{display:flex;flex-direction:column;align-items:flex-end;gap:8px}.card-header .type{margin:0;color:var(--color-text-neutral-disabled)}.card-footer{display:flex;justify-content:space-between;align-items:center;margin-top:auto;padding-top:12px;border-top:1px solid var(--color-border-surface-on-elevation-1);flex-shrink:0}.card-footer .description{margin:0;line-height:var(--line-height-relaxed);color:var(--color-text-neutral-default)}.card-footer .angular-icon{inline-size:14px;block-size:14px;opacity:0.8}.no-results,.no-objects{color:var(--color-text-neutral-disabled);text-align:center;padding:16px}.recent-objects-grid-container .cell-content{display:flex;align-items:center;gap:var(--spacing-gap-m)}.tabular-grid-scroll-container{max-block-size:400px;overflow-y:auto;overflow-x:hidden;scrollbar-width:thin}:host{display:block !important}.header{display:block !important;inline-size:100% !important;float:none !important;clear:both !important}.field{display:block !important;inline-size:100% !important;float:none !important;clear:both !important}.main{display:block !important;inline-size:100% !important;float:none !important;clear:both !important}";

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 __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 _GxIdeLaunchpadWebApps_instances, _GxIdeLaunchpadWebApps_componentLocale, _GxIdeLaunchpadWebApps_filterObjects, _GxIdeLaunchpadWebApps_sortRecentObjects, _GxIdeLaunchpadWebApps_getObjectValue, _GxIdeLaunchpadWebApps_handleColumnSortChanged, _GxIdeLaunchpadWebApps_getObjectTypeIcon, _GxIdeLaunchpadWebApps_handleObjectClick, _GxIdeLaunchpadWebApps_renderMainObjects, _GxIdeLaunchpadWebApps_renderRecentObjects;
const CSS_BUNDLES = [
    "resets/box-sizing",
    "components/edit",
    "components/accordion",
    "components/tabular-grid",
    "components/icon",
    "chameleon/scrollbar",
    "utils/layout",
    "utils/form",
    "utils/typography",
    "utils/spacing",
    "utils/elevation"
];
const ANGULAR_LOGO = getAssetPath("./gx-ide-assets/launchpad-web-apps/images/angular-logo.svg");
const ACCORDION_RECENT_OBJECTS_ID = "recent-objects";
const COLUMN_NAME = "name";
const COLUMN_MODULE = "module";
const COLUMN_TYPE = "type";
const COLUMN_DESCRIPTION = "description";
const GxIdeLaunchpadWebApps = /*@__PURE__*/ proxyCustomElement(class GxIdeLaunchpadWebApps extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.__attachShadow();
        this.copyToClipboard = createEvent(this, "copyToClipboard", 7);
        _GxIdeLaunchpadWebApps_instances.add(this);
        _GxIdeLaunchpadWebApps_componentLocale.set(this, void 0);
        /**
         * Sorts recent objects
         */
        _GxIdeLaunchpadWebApps_sortRecentObjects.set(this, (a, b) => {
            var _a, _b;
            if (this.order.orderCriteria) {
                const orderCriteriaA = ((_a = __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_instances, "m", _GxIdeLaunchpadWebApps_getObjectValue).call(this, a, this.order.orderCriteria)) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || "";
                const orderCriteriaB = ((_b = __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_instances, "m", _GxIdeLaunchpadWebApps_getObjectValue).call(this, b, this.order.orderCriteria)) === null || _b === void 0 ? void 0 : _b.toUpperCase()) || "";
                if (orderCriteriaA < orderCriteriaB) {
                    return this.order.ascending ? -1 : 1;
                }
                if (orderCriteriaA > orderCriteriaB) {
                    return this.order.ascending ? 1 : -1;
                }
            }
            return 0;
        });
        /**
         * Handles column sort changes
         */
        _GxIdeLaunchpadWebApps_handleColumnSortChanged.set(this, (e) => {
            const { columnId, sortDirection } = e.detail;
            this.order = {
                orderCriteria: columnId,
                ascending: sortDirection === "asc"
            };
        });
        this.objects = [];
        this.onObjectSelected = undefined;
        this.filterValue = "";
        this.recentObjectsExpanded = true;
        this.order = {
            orderCriteria: null,
            ascending: null
        };
    }
    async componentWillLoad() {
        try {
            __classPrivateFieldSet(this, _GxIdeLaunchpadWebApps_componentLocale, await Locale.getComponentStrings(this.el), "f");
        }
        catch (error) {
            console.error("Error loading locale:", error);
            __classPrivateFieldSet(this, _GxIdeLaunchpadWebApps_componentLocale, {}, "f");
        }
    }
    handleAccordionExpandedChange(e) {
        if (e.detail.id === ACCORDION_RECENT_OBJECTS_ID) {
            this.recentObjectsExpanded = e.detail.expanded;
        }
    }
    render() {
        var _a, _b, _c;
        if (!this.objects || this.objects.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, _GxIdeLaunchpadWebApps_componentLocale, "f")) === null || _a === void 0 ? void 0 : _a.noData) ||
                "No web applications data available"))));
        }
        return (h(Host, null, h("ch-theme", { model: CSS_BUNDLES }), h("header", { class: "header dialog-header" }, h("div", { class: "field field-block" }, h("ch-edit", { class: "input input-filter", id: "filter", placeholder: ((_b = __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_componentLocale, "f")) === null || _b === void 0 ? void 0 : _b.search) || "Search", value: this.filterValue, accessibleName: ((_c = __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_componentLocale, "f")) === null || _c === void 0 ? void 0 : _c.search) || "Search", onInput: e => (this.filterValue = String(e.detail)) }))), h("div", { class: "main" }, h("ch-accordion-render", { class: "accordion-filled-header elevation-1 web-apps-accordion", model: [
                {
                    id: "main-objects",
                    caption: "Main Objects",
                    expanded: true
                },
                {
                    id: ACCORDION_RECENT_OBJECTS_ID,
                    caption: "Recent Objects",
                    expanded: this.recentObjectsExpanded
                }
            ] }, h("div", { slot: "main-objects", class: "accordion-content spacing-body" }, __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_instances, "m", _GxIdeLaunchpadWebApps_renderMainObjects).call(this)), h("div", { slot: ACCORDION_RECENT_OBJECTS_ID, class: "accordion-content spacing-body" }, __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_instances, "m", _GxIdeLaunchpadWebApps_renderRecentObjects).call(this))))));
    }
    static get assetsDirs() { return ["gx-ide-assets/launchpad-web-apps"]; }
    get el() { return this; }
    static get style() { return launchpadWebAppsCss; }
}, [1, "gx-ide-launchpad-web-apps", {
        "objects": [16],
        "onObjectSelected": [16],
        "filterValue": [32],
        "recentObjectsExpanded": [32],
        "order": [32]
    }, [[0, "expandedChange", "handleAccordionExpandedChange"]]]);
_GxIdeLaunchpadWebApps_componentLocale = new WeakMap(), _GxIdeLaunchpadWebApps_sortRecentObjects = new WeakMap(), _GxIdeLaunchpadWebApps_handleColumnSortChanged = new WeakMap(), _GxIdeLaunchpadWebApps_instances = new WeakSet(), _GxIdeLaunchpadWebApps_filterObjects = function _GxIdeLaunchpadWebApps_filterObjects(object) {
    if (!this.filterValue)
        return true;
    const filterV = this.filterValue.toLowerCase();
    return ((object.module && object.module.toLowerCase().includes(filterV)) ||
        (object.name && object.name.toLowerCase().includes(filterV)) ||
        (object.type && object.type.toLowerCase().includes(filterV)) ||
        (object.description && object.description.toLowerCase().includes(filterV)));
}, _GxIdeLaunchpadWebApps_getObjectValue = function _GxIdeLaunchpadWebApps_getObjectValue(obj, key) {
    switch (key) {
        case "name":
            return obj.name || "";
        case "module":
            return obj.module || "";
        case "type":
            return obj.type || "";
        case "description":
            return obj.description || "";
        default:
            return "";
    }
}, _GxIdeLaunchpadWebApps_getObjectTypeIcon = function _GxIdeLaunchpadWebApps_getObjectTypeIcon(object) {
    var _a;
    const iconMap = {
        "36e32e2d-023e-4188-95df-d13573bac2e0:API": getIconPath({
            category: "objects",
            name: "api"
        }),
        "2a9e9aba-d2de-4801-ae7f-5e3819222daf:Data Provider": getIconPath({
            category: "objects",
            name: "data-provider"
        }),
        "9bdcc055-174e-4af6-96cb-a2ceef6c5f09:Menu": getIconPath({
            category: "objects",
            name: "dashboard"
        }),
        "9bdcc055-174e-4af6-96cb-a2ceef6c5f09:Dashboard": getIconPath({
            category: "objects",
            name: "dashboard"
        }),
        "0eee17f4-cef9-4988-aed4-c2da632be85b:Mini App": getIconPath({
            category: "objects",
            name: "mini-app"
        }),
        "d82625fd-5892-40b0-99c9-5c8559c197fc:Panel": getIconPath({
            category: "objects",
            name: "panel-for-sd"
        }),
        "d82625fd-5892-40b0-99c9-5c8559c197fc:SDPanel": getIconPath({
            category: "objects",
            name: "panel-for-sd"
        }),
        "84a12160-f59b-4ad7-a683-ea4481ac23e9:Procedure": getIconPath({
            category: "objects",
            name: "procedure"
        }),
        "a7e6cce5-1171-49e9-a6a0-07f137eedc07:Super App": getIconPath({
            category: "objects",
            name: "super-app"
        }),
        "1db606f2-af09-4cf9-a3b5-b481519d28f6:Transaction": getIconPath({
            category: "objects",
            name: "transaction"
        }),
        "c9584656-94b6-4ccd-890f-332d11fc2c25:Web Panel": getIconPath({
            category: "objects",
            name: "webpanel"
        }),
        "c9584656-94b6-4ccd-890f-332d11fc2c25:WebPanel": getIconPath({
            category: "objects",
            name: "webpanel"
        }),
        "c9584656-94b6-4ccd-890f-332d11fc2c25:Web Component": getIconPath({
            category: "objects",
            name: "web-component"
        }),
        "c9584656-94b6-4ccd-890f-332d11fc2c25:WebComponent": getIconPath({
            category: "objects",
            name: "web-component"
        }),
        "15cf49b5-fc38-4899-91b5-395d02d79889:Work With": getIconPath({
            category: "patterns",
            name: "workwith-for-sd"
        }),
        "15cf49b5-fc38-4899-91b5-395d02d79889:WorkWith": getIconPath({
            category: "patterns",
            name: "workwith-for-sd"
        }),
        "API": getIconPath({ category: "objects", name: "api" }),
        "Data Provider": getIconPath({
            category: "objects",
            name: "data-provider"
        }),
        "Menu": getIconPath({ category: "objects", name: "dashboard" }),
        "Dashboard": getIconPath({ category: "objects", name: "dashboard" }),
        "Mini App": getIconPath({ category: "objects", name: "mini-app" }),
        "Panel": getIconPath({ category: "objects", name: "panel-for-sd" }),
        "SDPanel": getIconPath({ category: "objects", name: "panel-for-sd" }),
        "Procedure": getIconPath({ category: "objects", name: "procedure" }),
        "Super App": getIconPath({ category: "objects", name: "super-app" }),
        "Transaction": getIconPath({ category: "objects", name: "transaction" }),
        "Web Panel": getIconPath({ category: "objects", name: "webpanel" }),
        "WebPanel": getIconPath({ category: "objects", name: "webpanel" }),
        "Web Component": getIconPath({
            category: "objects",
            name: "web-component"
        }),
        "WebComponent": getIconPath({
            category: "objects",
            name: "web-component"
        }),
        "Work With": getIconPath({
            category: "patterns",
            name: "workwith-for-sd"
        }),
        "WorkWith": getIconPath({ category: "patterns", name: "workwith-for-sd" })
    };
    if ((_a = object.key) === null || _a === void 0 ? void 0 : _a.type) {
        const fullKey = `${object.key.type}:${object.type}`;
        if (iconMap[fullKey]) {
            return iconMap[fullKey];
        }
    }
    if (iconMap[object.type]) {
        return iconMap[object.type];
    }
    return getIconPath({ category: "objects", name: "object" });
}, _GxIdeLaunchpadWebApps_handleObjectClick = function _GxIdeLaunchpadWebApps_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 } });
    }
}, _GxIdeLaunchpadWebApps_renderMainObjects = function _GxIdeLaunchpadWebApps_renderMainObjects() {
    var _a, _b, _c;
    const mainObjects = ((_a = this.objects.find(obj => obj.type === "main")) === null || _a === void 0 ? void 0 : _a.objects) || [];
    const filteredObjects = mainObjects.filter(obj => __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_instances, "m", _GxIdeLaunchpadWebApps_filterObjects).call(this, obj));
    if (mainObjects.length === 0) {
        return (h("div", { class: "no-results" }, h("p", { class: "body-regular-s" }, ((_b = __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_componentLocale, "f")) === null || _b === void 0 ? void 0 : _b.noMainObjects) ||
            "There are no main objects to display")));
    }
    if (filteredObjects.length === 0) {
        return (h("div", { class: "no-results" }, h("p", { class: "body-regular-s" }, (_c = __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_componentLocale, "f")) === null || _c === void 0 ? void 0 : _c.noObjectsMatchSearch)));
    }
    return (h("div", { class: "main-objects-grid" }, filteredObjects.map((object, index) => (h("button", { key: index, class: "object-card elevation-1", onClick: () => __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_instances, "m", _GxIdeLaunchpadWebApps_handleObjectClick).call(this, object) }, h("div", { class: "card-header" }, h("div", { class: "left" }, h("h1", { class: "name body-semi-bold-s" }, object.name), h("h3", { class: "module body-regular-xs" }, object.module), h("p", { class: "type body-italic-xs" }, object.type)), h("div", { class: "right" }, h("div", { class: "type-container" }, h("ch-image", { class: "type-icon icon-m", src: __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_instances, "m", _GxIdeLaunchpadWebApps_getObjectTypeIcon).call(this, object) })))), (object.description || object.angular) && (h("footer", { class: "card-footer" }, h("div", { class: "left" }, object.description && (h("p", { class: "description body-regular-xs" }, object.description))), h("div", { class: "right" }, object.angular && (h("img", { src: ANGULAR_LOGO, alt: "Angular Logotype" })))))))), 
    // WA: Add empty divs to ensure a minimum of 4 grid items for proper layout
    filteredObjects.length < 4 &&
        Array.from({ length: 4 - filteredObjects.length }).map((_, index) => h("div", { key: `empty-${index}` }))));
}, _GxIdeLaunchpadWebApps_renderRecentObjects = function _GxIdeLaunchpadWebApps_renderRecentObjects() {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
    const recentObjects = ((_a = this.objects.find(obj => obj.type === "recent")) === null || _a === void 0 ? void 0 : _a.objects) || [];
    const filteredObjects = recentObjects.filter(obj => __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_instances, "m", _GxIdeLaunchpadWebApps_filterObjects).call(this, obj));
    if (recentObjects.length === 0) {
        return (h("div", { class: "no-objects" }, h("p", { class: "body-regular-s" }, (_b = __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_componentLocale, "f")) === null || _b === void 0 ? void 0 : _b.noRecentObjects)));
    }
    if (filteredObjects.length === 0) {
        return (h("div", { class: "no-objects" }, h("p", { class: "body-regular-s" }, (_c = __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_componentLocale, "f")) === null || _c === void 0 ? void 0 : _c.noObjectsMatchSearch)));
    }
    const sortedObjects = [...filteredObjects].sort(__classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_sortRecentObjects, "f"));
    return (h("div", { class: "recent-objects-grid-container" }, h("div", { class: "tabular-grid-scroll-container" }, h("ch-tabular-grid", { class: "tabular-grid elevation-2" }, h("ch-tabular-grid-columnset", { class: "tabular-grid-column-set" }, h("ch-tabular-grid-column", { class: "tabular-grid-column", columnId: COLUMN_NAME, columnName: ((_e = (_d = __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_componentLocale, "f")) === null || _d === void 0 ? void 0 : _d.columns) === null || _e === void 0 ? void 0 : _e.name) || "Name", columnNameHidden: false, settingable: false, sortable: true, onColumnSortChanged: __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_handleColumnSortChanged, "f"), size: "25%", resizable: false }), h("ch-tabular-grid-column", { class: "tabular-grid-column", columnId: COLUMN_MODULE, columnName: ((_g = (_f = __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_componentLocale, "f")) === null || _f === void 0 ? void 0 : _f.columns) === null || _g === void 0 ? void 0 : _g.module) || "Module", columnNameHidden: false, settingable: false, sortable: true, onColumnSortChanged: __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_handleColumnSortChanged, "f"), size: "20%", resizable: false }), h("ch-tabular-grid-column", { class: "tabular-grid-column", columnId: COLUMN_TYPE, columnName: ((_j = (_h = __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_componentLocale, "f")) === null || _h === void 0 ? void 0 : _h.columns) === null || _j === void 0 ? void 0 : _j.type) || "Type", columnNameHidden: false, settingable: false, sortable: true, onColumnSortChanged: __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_handleColumnSortChanged, "f"), size: "20%", resizable: false }), h("ch-tabular-grid-column", { class: "tabular-grid-column", columnId: COLUMN_DESCRIPTION, columnName: ((_l = (_k = __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_componentLocale, "f")) === null || _k === void 0 ? void 0 : _k.columns) === null || _l === void 0 ? void 0 : _l.description) || "Description", columnNameHidden: false, settingable: false, sortable: false, size: "35%", resizable: false })), h("ch-tabular-grid-rowset", { class: "tabular-grid-rowset" }, sortedObjects.map((obj, index) => {
        var _a;
        return (h("ch-tabular-grid-row", { rowid: ((_a = obj.key) === null || _a === void 0 ? void 0 : _a.id) || index.toString(), class: "tabular-grid-row", onClick: () => __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_instances, "m", _GxIdeLaunchpadWebApps_handleObjectClick).call(this, obj) }, h("ch-tabular-grid-cell", { class: "tabular-grid-cell" }, h("div", { class: "cell-content" }, h("ch-image", { class: "object-icon icon-m", src: __classPrivateFieldGet(this, _GxIdeLaunchpadWebApps_instances, "m", _GxIdeLaunchpadWebApps_getObjectTypeIcon).call(this, obj) }), h("span", { class: "object-name" }, obj.name || "Unnamed"))), h("ch-tabular-grid-cell", { class: "tabular-grid-cell" }, obj.module || ""), h("ch-tabular-grid-cell", { class: "tabular-grid-cell" }, obj.type), h("ch-tabular-grid-cell", { class: "tabular-grid-cell" }, obj.description || "")));
    }))))));
};
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["gx-ide-launchpad-web-apps"];
    components.forEach(tagName => { switch (tagName) {
        case "gx-ide-launchpad-web-apps":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, GxIdeLaunchpadWebApps);
            }
            break;
    } });
}

export { GxIdeLaunchpadWebApps as G, defineCustomElement as d };

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