import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
import { c as config } from './config.js';
import { L as Locale } from './locale.js';
import { r as renderListItems } from './render-list-item.js';
import { d as defineCustomElement$3 } from './container.js';
import { d as defineCustomElement$2 } from './list-selector.js';
import { d as defineCustomElement$1 } from './list-selector-item.js';

const objectsToListItemData = (objects) => {
    const itemsData = [];
    objects.forEach(object => {
        const itemId = object.id;
        const itemValue = object.name;
        const itemIcon = object.icon;
        const itemChecked = false;
        itemsData.push({
            itemId: itemId,
            itemValue: itemValue,
            itemIcon: itemIcon,
            itemChecked: itemChecked
        });
    });
    return itemsData;
};

const bpmObjectsSelectorCss = ":host{display:grid;block-size:100%}.opacity-0{opacity:0}.gxi-hidden{display:none !important}.align-center{display:flex;align-items:center}.align-end{display:flex;align-items:end}.overflow-auto{overflow:auto}:host(.gx-ide-component){height:100% !important;display:flex !important;flex-direction:column !important}.gx-ide-main-wrapper{color:var(--gx-ide-component-text-color);font-weight:var(--font-style-regular);font-size:var(--font-size-body-m);font-family:var(--font-family-body);height:100%;display:flex;flex-direction:column;flex-grow:1;box-sizing:border-box}.buttons-container{display:flex;gap:var(--spacing-gap-m)}.giu-static-pill-icon-and-text,.giu-static-pill{background-color:var(--elevation-background-color, var(--color-accent-surface-elevation-1));padding-inline:var(--spacing-padding-m);color:var(--color-text-neutral-default);font-size:var(--font-size-body-s);line-height:var(--line-height-relaxed);font-weight:var(--font-style-regular);border-radius:4px;min-block-size:25px;display:inline-grid;align-items:center;pointer-events:none;inline-size:max-content}.giu-static-pill-icon-and-text{display:inline-grid;grid-auto-flow:column;grid-auto-columns:max-content;gap:var(--spacing-gap-m)}.tab-full-width-buttons::part(tab-list block-start),.tab-full-width-buttons::part(tab-list block-end){grid-auto-columns:1fr}.tab-full-width-buttons::part(tab block-start){justify-content:center}.tree-view::part(item__header){--icon__system_warning_warning--disabled:var(\n    --icon__system_warning_warning--enabled\n  )}.tabular-grid{--focus-outline-width:1px}.control-wrapper{display:flex;gap:var(--spacing-gap-m);align-items:center}.control-wrapper--vertical{flex-direction:column;align-items:start}.controls-wrapper{display:flex;gap:var(--spacing-gap-m)}.controls-wrapper--vertical{flex-direction:column;align-items:start}.input-text{box-sizing:border-box;background-color:transparent;border:1px solid var(--color-border-neutral-default);border-radius:4px;height:26px;color:var(--color-text-neutral-default);font-size:var(--font-size-body-xs)}.input-text--full-width{align-self:stretch}:host{display:block}.header{display:grid;grid-template-columns:1fr min-content min-content;grid-template-areas:\"label label label\" \"input cancel export\";grid-gap:var(--spacing-gap-l)}.header .label{grid-area:label}.header .input{grid-area:input}.header .cancel{grid-area:cancel}.header .export{grid-area:export}";

const GxIdeBpmExportXpdl = /*@__PURE__*/ proxyCustomElement(class GxIdeBpmExportXpdl extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.__attachShadow();
        this.componentDidRenderFirstTime = createEvent(this, "componentDidRenderFirstTime", 7);
        this.selectionChanged = createEvent(this, "selectionChanged", 7);
        this.renderedFirstTime = false;
        this.includeAll = false;
        // 7.LISTENERS //
        // 8.PUBLIC METHODS API //
        // 9.LOCAL METHODS //
        this.objectSelectionChangedHandler = (selectedItem) => {
            const selectedObjects = Array.isArray(selectedItem.detail)
                ? selectedItem.detail
                : [selectedItem.detail];
            this.selectedObjects = selectedObjects.map(item => item.itemId);
        };
        this.removeObjectsHandler = () => {
            this.objects = this.objects.filter(object => !this.selectedObjects.includes(object.id));
            this.selectedObjects = [];
            this.updateSelection(false);
        };
        this.removeAllObjectsHandler = () => {
            this.objects = [];
            this.selectedObjects = [];
            this.updateSelection(false);
        };
        this.includeAllHandler = () => {
            this.includeAll = this.includeAllCheckboxEl.value === "true";
            if (this.includeAll) {
                this.selectedObjects = this.objects.map(object => object.id);
                this.objects = [];
                this.updateSelection(true);
            }
            else {
                this.selectedObjects = [];
                this.updateSelection(false);
            }
            this.selectionChanged.emit();
        };
        this.addCallbackHandler = async () => {
            if (this.addCallback) {
                const resultObjects = await this.addCallback();
                const newObjects = resultObjects.filter(resultObj => !this.objects.some(existingObj => existingObj.id === resultObj.id));
                this.objects = [...this.objects, ...newObjects];
                this.updateSelection(false);
            }
        };
        this.referencesCallbackHandler = async () => {
            if (this.referencesCallback && this.objects.length > 0) {
                const ids = this.objects.map(obj => obj.id);
                const resultObjects = await this.referencesCallback(ids);
                const newObjects = resultObjects.filter(resultObj => !this.objects.some(existingObj => existingObj.id === resultObj.id));
                this.objects = [...this.objects, ...newObjects];
                this.updateSelection(false);
            }
        };
        this.updateSelection = (includeAll) => {
            const data = {
                includeAll: this.includeAllCheckboxEl.value === "true",
                objectIds: includeAll
                    ? this.selectedObjects
                    : this.objects.map(object => object.id)
            };
            this.selection = data;
            this.selectionChanged.emit();
        };
        this.objects = [];
        this.selectedObjects = [];
        this.displayTitle = false;
        this.selection = undefined;
        this.addCallback = undefined;
        this.referencesCallback = undefined;
    }
    // 6.COMPONENT LIFECYCLE METHODS //
    async componentWillLoad() {
        this._componentLocale = await Locale.getComponentStrings(this.el);
    }
    componentDidRender() {
        if (!this.renderedFirstTime) {
            this.componentDidRenderFirstTime.emit(this.el);
            this.renderedFirstTime = true;
        }
    }
    // 10.RENDER() FUNCTION //
    render() {
        return (h(Host, { class: "gx-ide-component gx-ide-bpm-objects-selector" }, h("div", { class: "gx-ide-main-wrapper" }, h("gx-ide-container", { slimmerFooter: config.gxIdeContainer.slimmerFooter }, h("gx-ide-list-selector", { id: "path-list", type: "multi-selection", listName: "path-list", ordered: true, onSelectionChanged: this.objectSelectionChangedHandler, class: "path-list" }, renderListItems(objectsToListItemData(this.objects))), h("div", { class: "controls-wrapper" }, h("label", { htmlFor: "include-all" }, this._componentLocale.main.includeAllLabel), h("ch-checkbox", { id: "include-all", accessibleName: this._componentLocale.main.includeAllLabel, checkedValue: "true", unCheckedValue: "false", value: "checked", onInput: this.includeAllHandler, ref: (el) => (this.includeAllCheckboxEl = el) }), h("button", { onClick: this.addCallbackHandler, disabled: this.includeAll }, this._componentLocale.main.addButton), h("button", { onClick: this.referencesCallbackHandler, disabled: this.objects.length === 0 }, this._componentLocale.main.referencesButton), h("button", { onClick: this.removeObjectsHandler, disabled: this.selectedObjects.length === 0 || this.includeAll }, this._componentLocale.main.removeButton, " (", this.selectedObjects.length, ")")), h("button", { slot: "footer-end", onClick: this.removeAllObjectsHandler, disabled: this.includeAll }, this._componentLocale.main.clearButton)))));
    }
    static get assetsDirs() { return ["gx-ide-assets/bpm-objects-selector"]; }
    get el() { return this; }
    static get style() { return bpmObjectsSelectorCss; }
}, [1, "gx-ide-bpm-objects-selector", {
        "displayTitle": [4, "display-title"],
        "selection": [1040],
        "addCallback": [16],
        "referencesCallback": [16],
        "objects": [32],
        "selectedObjects": [32]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["gx-ide-bpm-objects-selector", "gx-ide-container", "gx-ide-list-selector", "gx-ide-list-selector-item"];
    components.forEach(tagName => { switch (tagName) {
        case "gx-ide-bpm-objects-selector":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, GxIdeBpmExportXpdl);
            }
            break;
        case "gx-ide-container":
            if (!customElements.get(tagName)) {
                defineCustomElement$3();
            }
            break;
        case "gx-ide-list-selector":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
        case "gx-ide-list-selector-item":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}

export { GxIdeBpmExportXpdl as G, defineCustomElement as d };

//# sourceMappingURL=bpm-objects-selector.js.map