import { r as registerInstance, c as createEvent, h, H as Host, a as getElement } from './index-b153bfd0.js';
import { L as Locale } from './locale-e5107fad.js';
import { c as config } from './config-5a775b7a.js';

const bpmAssignRolesCss = ":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}:host{display:block}.roles__container{display:grid;block-size:100%;box-sizing:border-box;grid-template-columns:1fr 1fr;gap:var(--spacing-gap-l)}.roles__role{display:grid;grid-template-rows:auto 1fr;overflow:auto}.roles__list{display:flex;flex-direction:column;block-size:100%;overflow:auto}.roles__list-header{display:grid;grid-template-rows:auto 1fr;gap:var(--spacing-gap-m)}.roles__list-title{background-color:var(--color-accent-surface-elevation-1);display:flex;align-items:center;justify-content:center}.add-remove-buttons{display:flex;justify-content:space-between}";

const GxIdeBpmAssignRoles = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.componentDidRenderFirstTime = createEvent(this, "componentDidRenderFirstTime", 7);
        this.renderedFirstTime = false;
        // 7.LISTENERS //
        // 8.PUBLIC METHODS API //
        // 9.LOCAL METHODS //
        this.confirmCallbackHandler = () => {
            this.confirmCallback(this.assignedRolesState);
        };
        this.cancelCallbackHandler = () => {
            this.cancelCallback();
        };
        this.handleAssignedCheckedChange = (e) => {
            this.assignedSelected = e.detail[0] && e.detail[0].checked === true;
        };
        this.handleUnassignedCheckedChange = (e) => {
            this.unassignedSelected = e.detail[0] && e.detail[0].checked === true;
        };
        this.handleUnassignedInput = (e) => {
            this.filterUnassignedInput = e.detail;
        };
        this.handleAssignedInput = (e) => {
            this.filterAssignedInput = e.detail;
        };
        this.getCheckedItems = (listBox) => {
            const checkedItems = [];
            const listBoxItems = listBox.querySelectorAll("gxg-list-box-item");
            listBoxItems.forEach((item) => {
                if (item.checked) {
                    checkedItems.push(item.value);
                }
            });
            return checkedItems;
        };
        this.addAll = () => {
            this.assignedRolesState = [
                ...this.assignedRolesState,
                ...this.unassignedRolesState
            ];
            this.unassignedRolesState = [];
        };
        this.addSelectedRoles = () => {
            const checkedItems = this.getCheckedItems(this.unassignedRolesEL);
            if (checkedItems.length) {
                this.unassignedRolesState = this.unassignedRolesState.filter(role => !checkedItems.includes(role));
                this.assignedRolesState = [...this.assignedRolesState, ...checkedItems];
                this.unassignedSelected = false;
            }
        };
        this.removeAll = () => {
            this.unassignedRolesState = [
                ...this.unassignedRolesState,
                ...this.assignedRolesState
            ];
            this.assignedRolesState = [];
        };
        this.removeSelectedRoles = () => {
            const checkedItems = this.getCheckedItems(this.assignedRolesEl);
            if (checkedItems.length) {
                this.assignedRolesState = this.assignedRolesState.filter(role => {
                    return !checkedItems.includes(role);
                });
                this.unassignedRolesState = [
                    ...this.unassignedRolesState,
                    ...checkedItems
                ];
                this.assignedSelected = false;
            }
        };
        this.renderRolesToAdd = () => {
            return (h("div", { class: "roles__list" }, h("gxg-list-box", { checkboxes: true, disabled: false, part: "add-roles-selection", onCheckedChanged: this.handleUnassignedCheckedChange, ref: (el) => (this.unassignedRolesEL = el), noBorder: true, borderBottom: true, borderStart: true, borderEnd: true }, this.unassignedRolesState
                .filter(role => this.filterUnassignedInput.toLowerCase() === "" ||
                role
                    .toLowerCase()
                    .includes(this.filterUnassignedInput.toLowerCase()))
                .map(role => (h("gxg-list-box-item", { value: role, checkbox: true, key: `${role}-${this.assignedRolesState.includes(role)
                    ? "assigned"
                    : "unassigned"}` }, role))))));
        };
        this.renderRolesToRemove = () => {
            return (h("div", { class: "roles__list" }, h("gxg-list-box", { checkboxes: true, disabled: false, part: "remove-roles-selection", onCheckedChanged: this.handleAssignedCheckedChange, ref: (el) => (this.assignedRolesEl = el), noBorder: true, borderBottom: true, borderStart: true, borderEnd: true }, this.assignedRolesState
                .filter(role => this.filterAssignedInput.toLowerCase() === "" ||
                role
                    .toLowerCase()
                    .includes(this.filterAssignedInput.toLowerCase()))
                .map(role => (h("gxg-list-box-item", { value: role, checkbox: true, key: `${role}-${this.assignedRolesState.includes(role)
                    ? "assigned"
                    : "unassigned"}` }, role))))));
        };
        this.unassignedRolesState = [];
        this.assignedRolesState = [];
        this.filterUnassignedInput = "";
        this.filterAssignedInput = "";
        this.unassignedSelected = false;
        this.assignedSelected = false;
        this.displayTitle = false;
        this.roles = undefined;
        this.assignedRoles = undefined;
        this.confirmCallback = undefined;
        this.cancelCallback = undefined;
    }
    // 6.COMPONENT LIFECYCLE METHODS //
    async componentWillLoad() {
        this._componentLocale = await Locale.getComponentStrings(this.el);
        this.unassignedRolesState = this.roles.filter(role => !this.assignedRoles.includes(role));
        this.assignedRolesState = this.assignedRoles;
    }
    componentDidRender() {
        if (!this.renderedFirstTime) {
            this.componentDidRenderFirstTime.emit(this._componentLocale.componentName);
            this.renderedFirstTime = true;
        }
    }
    // 10.RENDER() FUNCTION //
    render() {
        return (h(Host, { class: "gx-ide-component" }, h("div", { class: "gx-ide-main-wrapper" }, h("gx-ide-container", { noAboveFooterPadding: true, slimmerFooter: config.gxIdeContainer.slimmerFooter }, h("div", { class: "roles__container" }, h("section", { class: "roles__role" }, h("header", { class: "roles__list-header" }, h("gxg-form-text", { label: this._componentLocale.main.assignRoles.searchRoles, placeholder: this._componentLocale.main.assignRoles.placeholder, labelPosition: "above", clearButton: true, part: "add-roles-filter", class: { "add-roles-filter": true }, onInput: this.handleUnassignedInput }), h("div", { class: "roles__list-title" }, h("gxg-title", { type: "title-04" }, this._componentLocale.main.assignRoles.title), h("gxg-icon", { type: "navigation/chevron-right", color: "mercury-neutral" }))), this.renderRolesToAdd()), h("section", { class: "roles__role" }, h("header", { class: "roles__list-header" }, h("gxg-form-text", { label: this._componentLocale.main.removeRoles.searchRoles, placeholder: this._componentLocale.main.removeRoles.placeholder, labelPosition: "above", clearButton: true, part: "remove-roles-filter", class: { "remove-roles-filter": true }, onInput: this.handleAssignedInput }), h("div", { class: "roles__list-title" }, h("gxg-icon", { type: "navigation/chevron-left", color: "mercury-neutral" }), h("gxg-title", { type: "title-04" }, this._componentLocale.main.removeRoles.title))), this.renderRolesToRemove())), h("footer", { class: "add-remove-buttons", slot: "footer-above" }, h("footer", { class: "add-remove-buttons__add" }, h("gxg-button", { id: "add-all", part: "add-all-roles-btn", onClick: this.addAll, disabled: this.unassignedRolesState.length === 0, type: "secondary-text-only" }, this._componentLocale.main.assignRoles.addAllButton), h("gxg-button", { id: "add-selected", part: "add-selected-roles-btn", onClick: this.addSelectedRoles, disabled: !this.unassignedSelected ||
                !this.unassignedRolesState.length, type: "secondary-text-only" }, this._componentLocale.main.assignRoles.addSelectedButton)), h("footer", { class: "add-remove-buttons__remove" }, h("gxg-button", { id: "add-all", part: "remove-all-roles-btn", onClick: this.removeAll, disabled: this.assignedRolesState.length === 0, type: "secondary-text-only" }, this._componentLocale.main.removeRoles.removeAllButton), h("gxg-button", { id: "add-selected", part: "remove-selected-roles-btn", onClick: this.removeSelectedRoles, disabled: !this.assignedSelected || !this.assignedRolesState.length, type: "secondary-text-only" }, this._componentLocale.main.removeRoles.removeSelectedButton))), h("gxg-button", { type: "outlined", slot: "footer-end", onClick: this.cancelCallbackHandler }, this._componentLocale.footer.cancelButton), h("gxg-button", { slot: "footer-end", onClick: this.confirmCallbackHandler }, this._componentLocale.footer.confirmButton)))));
    }
    static get assetsDirs() { return ["gx-ide-assets/bpm-assign-roles"]; }
    get el() { return getElement(this); }
};
GxIdeBpmAssignRoles.style = bpmAssignRolesCss;

export { GxIdeBpmAssignRoles as gx_ide_bpm_assign_roles };

//# sourceMappingURL=gx-ide-bpm-assign-roles.entry.js.map