'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-75aef097.js');
const assetsManager = require('./assets-manager-089e91b1.js');
require('./mer-animated-dots-78490ca4.js');
require('lit');
require('lit/directives/when.js');
require('lit/directives/if-defined.js');
const locale = require('./locale-ff30a5f3.js');
const config = require('./config-3bb95f39.js');

const pluginExplorerCss = ":host{display:grid;block-size:100%;position:relative}.outer-container{grid-template-rows:max-content 1fr}.inner-container{position:relative}.list-box::part(item){width:100%;min-width:100%}.list-box::part(item__action){gap:var(--spacing-gap-xs)}.list-box::part(item__caption){font-weight:var(--font-style-semi-bold)}.list-box::part(custom-container){display:flex;flex-direction:column;gap:var(--spacing-gap-xs);width:100%}.list-box::part(custom-image){block-size:32px;inline-size:32px;margin-inline-end:12px}.list-box::part(custom-description){font-size:var(--font-size-body-s);margin:0;opacity:0.8;line-height:var(--line-height-relaxed);margin-inline-end:8px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.list-box::part(item__block-end start){width:100%;min-width:100%}.list-box::part(custom-brand){font-weight:var(--font-style-semi-bold);display:flex;gap:var(--spacing-gap-xs);align-items:center}.list-box::part(custom-brand-icon){--icon-path:var(--icon__system_user_neutral--enabled);display:inline-block;background-image:var(--icon-path);background-size:contain;background-repeat:no-repeat;background-position:center center;block-size:16px;inline-size:16px}.list-box::part(custom-button){--button-color:var(--color-text-primary-default);--button-color--enabled:var(--color-text-neutral-on-text);--button-color--active:var(--color-text-neutral-on-pressed);display:inline-grid;grid-auto-flow:column;grid-auto-columns:max-content;justify-content:center;padding-block:var(--control-padding-block);padding-inline:var(--control-padding-inline);box-sizing:border-box;color:var(--button-color);font-weight:var(--font-style-semi-bold);margin-block-end:auto;margin-block-start:auto;text-transform:capitalize}.list-box::part(custom-button):hover{--button-color:var(--color-text-primary-hover)}.list-box::part(custom-button):active{--button-color:var(--color-text-primary-pressed)}";

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 _GxIdePluginManager_componentLocale, _GxIdePluginManager_animateEmptyState, _GxIdePluginManager_actionListButtonClickHandler, _GxIdePluginManager_mapPluginDataToActionListModel, _GxIdePluginManager_pluginsFilterInputHandler, _GxIdePluginManager_evaluateContentToDisplay, _GxIdePluginManager_renderLoader, _GxIdePluginManager_pluginSelectedHandler;
const FILTER_ICON = assetsManager.getIconPath({
    category: "system",
    name: "filters",
    colorType: "on-surface"
});
// plugin icon if no iconUrl was provided
const EXTENSION_ICON_IMG = index.getAssetPath(`./gx-ide-assets/plugin-manager/images/plugin-icon.svg`);
const CSS_BUNDLES = [
    "resets/box-sizing",
    "components/list-box",
    "components/button",
    "components/edit",
    "utils/form",
    "utils/layout",
    "utils/typography",
    "utils/spacing",
    "chameleon/scrollbar"
];
const GxIdePluginManager = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        /**
         * The component hard-coded strings translations.
         */
        // eslint-disable-next-line @stencil-community/own-props-must-be-private
        _GxIdePluginManager_componentLocale.set(this, void 0);
        _GxIdePluginManager_animateEmptyState.set(this, false);
        _GxIdePluginManager_actionListButtonClickHandler.set(this, (pluginId, action) => (event) => {
            event.stopPropagation();
            this.executeActionCallback(pluginId, action);
        });
        _GxIdePluginManager_mapPluginDataToActionListModel.set(this, (pluginsData) => {
            const pluginsActionListModel = [];
            const separatorItem = { type: "separator" };
            pluginsData === null || pluginsData === void 0 ? void 0 : pluginsData.forEach((pluginData, index$1) => {
                const hasActionButton = !!pluginData.action;
                const pluginItem = {
                    id: pluginData.id,
                    caption: pluginData.name,
                    imgSrc: pluginData.iconUrl,
                    type: "actionable",
                    additionalInformation: {
                        "stretch-start": {
                            center: [
                                {
                                    part: "custom-image",
                                    jsx: () => (index.h("img", { part: "custom-image", src: pluginData.iconUrl || EXTENSION_ICON_IMG, alt: `${__classPrivateFieldGet(this, _GxIdePluginManager_componentLocale, "f").logotype.replace("PLUGIN_NAME_PLACEHOLDER", pluginData.name)}`, loading: "lazy" }))
                                }
                            ]
                        },
                        "block-end": {
                            start: [
                                {
                                    part: "custom-description custom-button custom-container custom-brand custom-brand-icon custom-image item__block-end start",
                                    jsx: () => (index.h("div", { part: "custom-container", title: pluginData.description }, index.h("p", { part: "custom-description" }, pluginData.description), index.h("small", { part: "custom-brand" }, pluginData.publisher)))
                                }
                                // {
                                //   slot: "abcd"
                                // } as ActionListItemAdditionalSlot // slot not working
                            ]
                        },
                        "stretch-end": hasActionButton && {
                            center: [
                                {
                                    jsx: () => (index.h("button", { part: "custom-button", onClick: __classPrivateFieldGet(this, _GxIdePluginManager_actionListButtonClickHandler, "f").call(this, pluginData.id, pluginData.action) }, pluginData.action))
                                }
                            ]
                        }
                    }
                };
                if (index$1 !== 0) {
                    pluginsActionListModel.push(separatorItem);
                }
                pluginsActionListModel.push(pluginItem);
            });
            return pluginsActionListModel;
        });
        _GxIdePluginManager_pluginsFilterInputHandler.set(this, async (event) => {
            this.loading = true;
            const filterValue = event.detail;
            this.plugins = await this.filterCallback(filterValue);
        });
        _GxIdePluginManager_evaluateContentToDisplay.set(this, () => {
            const pluginsToDisplay = this.pluginsActionListModel.length;
            return pluginsToDisplay ? (index.h("ch-action-list-render", { model: this.pluginsActionListModel, class: "list-box", selection: "single", onSelectedItemsChange: __classPrivateFieldGet(this, _GxIdePluginManager_pluginSelectedHandler, "f") })) : (index.h("gx-ide-empty-state", { isAnimated: __classPrivateFieldGet(this, _GxIdePluginManager_animateEmptyState, "f"), class: "recent-objects__empty-state", stateIconSrc: FILTER_ICON, stateTitle: __classPrivateFieldGet(this, _GxIdePluginManager_componentLocale, "f").emptyStateTitle, stateDescription: __classPrivateFieldGet(this, _GxIdePluginManager_componentLocale, "f").emptyStateDescription }));
        });
        _GxIdePluginManager_renderLoader.set(this, () => {
            __classPrivateFieldSet(this, _GxIdePluginManager_animateEmptyState, true, "f");
            return (index.h("gx-ide-loader", { loaderTitle: __classPrivateFieldGet(this, _GxIdePluginManager_componentLocale, "f").loaderTitle, description: __classPrivateFieldGet(this, _GxIdePluginManager_componentLocale, "f").loaderDescription, show: true }));
        });
        _GxIdePluginManager_pluginSelectedHandler.set(this, (event) => {
            var _a;
            const eventType = (_a = event.detail[0]) === null || _a === void 0 ? void 0 : _a.item.type;
            if (eventType === "actionable") {
                const pluginId = event.detail[0].item.id;
                this.showDetailsCallback(pluginId);
            }
        });
        this.loading = true;
        this.pluginsActionListModel = [];
        this.plugins = undefined;
        this.filterCallback = undefined;
        this.showDetailsCallback = undefined;
        this.executeActionCallback = undefined;
    }
    pluginsChangedHandler(newPlugins) {
        this.pluginsActionListModel =
            __classPrivateFieldGet(this, _GxIdePluginManager_mapPluginDataToActionListModel, "f").call(this, newPlugins);
        this.loading = false;
    }
    async componentWillLoad() {
        __classPrivateFieldSet(this, _GxIdePluginManager_componentLocale, await locale.Locale.getComponentStrings(this.el), "f");
        this.pluginsChangedHandler(this.plugins);
    }
    render() {
        return (index.h(index.Host, { class: "widget" }, index.h("ch-theme", { model: CSS_BUNDLES }), index.h("div", { class: "outer-container field-group" }, index.h("ch-edit", { id: "search-plugins-input", class: "input", accessibleName: __classPrivateFieldGet(this, _GxIdePluginManager_componentLocale, "f").accessibleName, placeholder: __classPrivateFieldGet(this, _GxIdePluginManager_componentLocale, "f").searchInputPlaceholder, debounce: config.config.inputDebounce, onInput: __classPrivateFieldGet(this, _GxIdePluginManager_pluginsFilterInputHandler, "f"), type: "search" }), index.h("div", { class: "inner-container" }, this.loading
            ? __classPrivateFieldGet(this, _GxIdePluginManager_renderLoader, "f").call(this)
            : __classPrivateFieldGet(this, _GxIdePluginManager_evaluateContentToDisplay, "f").call(this)))));
    }
    static get assetsDirs() { return ["gx-ide-assets/plugin-explorer"]; }
    get el() { return index.getElement(this); }
    static get watchers() { return {
        "plugins": ["pluginsChangedHandler"]
    }; }
};
_GxIdePluginManager_componentLocale = new WeakMap(), _GxIdePluginManager_animateEmptyState = new WeakMap(), _GxIdePluginManager_actionListButtonClickHandler = new WeakMap(), _GxIdePluginManager_mapPluginDataToActionListModel = new WeakMap(), _GxIdePluginManager_pluginsFilterInputHandler = new WeakMap(), _GxIdePluginManager_evaluateContentToDisplay = new WeakMap(), _GxIdePluginManager_renderLoader = new WeakMap(), _GxIdePluginManager_pluginSelectedHandler = new WeakMap();
GxIdePluginManager.style = pluginExplorerCss;

exports.gx_ide_plugin_explorer = GxIdePluginManager;

//# sourceMappingURL=gx-ide-plugin-explorer.cjs.entry.js.map