import { Component, EventEmitter, Input, Output } from '@angular/core';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "primeng-lts/checkbox";
import * as i3 from "@angular/forms";
import * as i4 from "primeng-lts/tooltip";
function AlSelectableListComponent_div_0_div_2_Template(rf, ctx) { if (rf & 1) {
    const _r4 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 6);
    i0.ɵɵelementStart(1, "i", 7);
    i0.ɵɵlistener("click", function AlSelectableListComponent_div_0_div_2_Template_i_click_1_listener() { i0.ɵɵrestoreView(_r4); const ctx_r3 = i0.ɵɵnextContext(2); return ctx_r3.removeSelectedItems(); });
    i0.ɵɵtext(2, "clear");
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} }
function AlSelectableListComponent_div_0_Template(rf, ctx) { if (rf & 1) {
    const _r6 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 3);
    i0.ɵɵelementStart(1, "p-checkbox", 4);
    i0.ɵɵlistener("click", function AlSelectableListComponent_div_0_Template_p_checkbox_click_1_listener() { i0.ɵɵrestoreView(_r6); const ctx_r5 = i0.ɵɵnextContext(); return ctx_r5.toggleCheckAll(); })("ngModelChange", function AlSelectableListComponent_div_0_Template_p_checkbox_ngModelChange_1_listener($event) { i0.ɵɵrestoreView(_r6); const ctx_r7 = i0.ɵɵnextContext(); return ctx_r7.allChecked = $event; });
    i0.ɵɵelementEnd();
    i0.ɵɵtemplate(2, AlSelectableListComponent_div_0_div_2_Template, 3, 0, "div", 5);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngModel", ctx_r0.allChecked);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", !ctx_r0.readonly && ctx_r0.hasSelectedItems && ctx_r0.allowRemoval);
} }
function AlSelectableListComponent_div_2_i_5_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "i", 14);
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const option_r8 = i0.ɵɵnextContext().$implicit;
    i0.ɵɵproperty("pTooltip", option_r8.label);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate(option_r8.icon);
} }
function AlSelectableListComponent_div_2_i_6_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "i", 15);
} if (rf & 2) {
    const option_r8 = i0.ɵɵnextContext().$implicit;
    i0.ɵɵproperty("ngClass", option_r8.icon)("pTooltip", option_r8.label);
} }
function AlSelectableListComponent_div_2_div_10_Template(rf, ctx) { if (rf & 1) {
    const _r16 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 6);
    i0.ɵɵelementStart(1, "i", 7);
    i0.ɵɵlistener("click", function AlSelectableListComponent_div_2_div_10_Template_i_click_1_listener() { i0.ɵɵrestoreView(_r16); const option_r8 = i0.ɵɵnextContext().$implicit; const ctx_r14 = i0.ɵɵnextContext(); return ctx_r14.removeItem(option_r8); });
    i0.ɵɵtext(2, "clear");
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} }
function AlSelectableListComponent_div_2_Template(rf, ctx) { if (rf & 1) {
    const _r18 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div");
    i0.ɵɵelementStart(1, "div", 8);
    i0.ɵɵelementStart(2, "div");
    i0.ɵɵelementStart(3, "p-checkbox", 9);
    i0.ɵɵlistener("ngModelChange", function AlSelectableListComponent_div_2_Template_p_checkbox_ngModelChange_3_listener($event) { i0.ɵɵrestoreView(_r18); const option_r8 = ctx.$implicit; return option_r8.checked = $event; })("click", function AlSelectableListComponent_div_2_Template_p_checkbox_click_3_listener() { i0.ɵɵrestoreView(_r18); const ctx_r19 = i0.ɵɵnextContext(); return ctx_r19.toggleCheck(); });
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(4, "span", 10);
    i0.ɵɵtemplate(5, AlSelectableListComponent_div_2_i_5_Template, 2, 2, "i", 11);
    i0.ɵɵtemplate(6, AlSelectableListComponent_div_2_i_6_Template, 1, 2, "i", 12);
    i0.ɵɵtext(7);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(8, "span", 13);
    i0.ɵɵtext(9);
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
    i0.ɵɵtemplate(10, AlSelectableListComponent_div_2_div_10_Template, 3, 0, "div", 5);
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const option_r8 = ctx.$implicit;
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance(3);
    i0.ɵɵproperty("disabled", ctx_r1.readonly)("value", option_r8.value)("ngModel", option_r8.checked);
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("ngIf", option_r8.isMaterialIcon);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", !option_r8.isMaterialIcon);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate1(" ", option_r8.title, " ");
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", option_r8.subtitle, "");
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", !ctx_r1.readonly && ctx_r1.allowRemoval);
} }
export class AlSelectableListComponent {
    constructor() {
        // Array with the items on the checkbox format (AlSelectItem from multi-select-list component)
        this.options = [];
        // Readonly mode
        this.readonly = false;
        // allows removal items
        this.allowRemoval = true;
        // allows select All
        this.allowSelectAll = true;
        // Event Emitter with the selected options
        this.onSelectionChanged = new EventEmitter();
        // Control variable which controls the state of the select all checkbox.
        this.allChecked = false;
        this.hasSelectedItems = false;
    }
    /**
     * Function which removes the item from the options list.
     * @param item the item to be removed from the options list.
     */
    removeItem(item) {
        const index = this.options.indexOf(item);
        if (index !== -1) {
            this.options[index].checked = false;
            this.options.splice(index, 1);
        }
        this.toggleCheck();
        this.onSelectionChanged.emit(this.options);
    }
    /**
     * Function which toggles the options when clicking on the select all checkbox
     */
    toggleCheckAll() {
        this.options.forEach((option) => option.checked = this.allChecked);
        this.hasSelectedItems = this.allChecked;
    }
    /**
     * Function which toggles the hasSelectedItems and allChecked variable
     */
    toggleCheck() {
        if (this.options && this.options.length > 0) {
            this.allChecked = this.options.every(option => option.checked);
            this.hasSelectedItems = this.options.some((option) => option.checked);
        }
    }
    /**
     * Functions which iterates over the selected items and remove those.
     */
    removeSelectedItems() {
        this.options.filter((option) => option.checked).forEach(option => this.removeItem(option));
        this.toggleCheck();
        this.allChecked = false;
    }
}
/** @nocollapse */ AlSelectableListComponent.ɵfac = function AlSelectableListComponent_Factory(t) { return new (t || AlSelectableListComponent)(); };
/** @nocollapse */ AlSelectableListComponent.ɵcmp = i0.ɵɵdefineComponent({ type: AlSelectableListComponent, selectors: [["al-selectable-list"]], inputs: { options: "options", readonly: "readonly", allowRemoval: "allowRemoval", allowSelectAll: "allowSelectAll" }, outputs: { onSelectionChanged: "onSelectionChanged" }, decls: 3, vars: 2, consts: [["class", "toggle-select", 4, "ngIf"], [1, "options-container"], [4, "ngFor", "ngForOf"], [1, "toggle-select"], ["name", "toggle-select", "label", "Select All", "binary", "true", 3, "ngModel", "click", "ngModelChange"], ["class", "close-sign", 4, "ngIf"], [1, "close-sign"], [1, "material-icons", 3, "click"], [1, "item"], ["name", "items", "binary", "true", 3, "disabled", "value", "ngModel", "ngModelChange", "click"], [1, "selectable-title"], ["class", "material-icons", "tooltipPosition", "left", 3, "pTooltip", 4, "ngIf"], ["tooltipPosition", "left", 3, "ngClass", "pTooltip", 4, "ngIf"], [1, "subtitle"], ["tooltipPosition", "left", 1, "material-icons", 3, "pTooltip"], ["tooltipPosition", "left", 3, "ngClass", "pTooltip"]], template: function AlSelectableListComponent_Template(rf, ctx) { if (rf & 1) {
        i0.ɵɵtemplate(0, AlSelectableListComponent_div_0_Template, 3, 2, "div", 0);
        i0.ɵɵelementStart(1, "div", 1);
        i0.ɵɵtemplate(2, AlSelectableListComponent_div_2_Template, 11, 8, "div", 2);
        i0.ɵɵelementEnd();
    } if (rf & 2) {
        i0.ɵɵproperty("ngIf", ctx.options && ctx.options.length > 0 && !ctx.readonly && ctx.allowSelectAll);
        i0.ɵɵadvance(2);
        i0.ɵɵproperty("ngForOf", ctx.options);
    } }, directives: [i1.NgIf, i1.NgForOf, i2.Checkbox, i3.NgControlStatus, i3.NgModel, i4.Tooltip, i1.NgClass], styles: ["[_nghost-%COMP%]     .toggle-select{margin-bottom:10px;margin-top:10px;display:flex;font-size:14px;justify-content:space-between;border-bottom:1px solid #ededed}[_nghost-%COMP%]     .toggle-select .ui-chkbox-label{margin-left:0}[_nghost-%COMP%]     .options-container{max-height:35vh;overflow-y:auto}[_nghost-%COMP%]     .options-container .item{display:flex;align-items:center;justify-content:space-between;font-size:14px;padding-top:var(--ald-g-space-2)}[_nghost-%COMP%]     .options-container .item .selectable-title{font-weight:700;word-break:break-all}[_nghost-%COMP%]     .options-container .item .selectable-title .material-icons{font-size:14px}[_nghost-%COMP%]     .options-container .item .subtitle{font-weight:400}[_nghost-%COMP%]     .close-sign{cursor:pointer;display:flex;align-items:center}[_nghost-%COMP%]     .close-sign i{font-size:20px;color:#535353;height:24px;width:24px}"] });
/*@__PURE__*/ (function () { i0.ɵsetClassMetadata(AlSelectableListComponent, [{
        type: Component,
        args: [{
                selector: 'al-selectable-list',
                templateUrl: './al-selectable-list.component.html',
                styleUrls: ['./al-selectable-list.component.scss']
            }]
    }], null, { options: [{
            type: Input
        }], readonly: [{
            type: Input
        }], allowRemoval: [{
            type: Input
        }], allowSelectAll: [{
            type: Input
        }], onSelectionChanged: [{
            type: Output
        }] }); })();
//# sourceMappingURL=data:application/json;base64, 