import { __assign } from "tslib";
import { Component, Input, EventEmitter, Output } from '@angular/core';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
function AlSelectableChipsComponent_li_2_i_5_Template(rf, ctx) { if (rf & 1) {
    var _r8 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "i", 8);
    i0.ɵɵlistener("click", function AlSelectableChipsComponent_li_2_i_5_Template_i_click_0_listener() { i0.ɵɵrestoreView(_r8); var i_r4 = i0.ɵɵnextContext().index; var ctx_r6 = i0.ɵɵnextContext(); return ctx_r6.removeSelectedItemAt(i_r4, "and"); });
    i0.ɵɵelementEnd();
} }
function AlSelectableChipsComponent_li_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "li", 4);
    i0.ɵɵelementStart(1, "span", 5);
    i0.ɵɵelementStart(2, "strong");
    i0.ɵɵtext(3);
    i0.ɵɵelementEnd();
    i0.ɵɵtext(4);
    i0.ɵɵtemplate(5, AlSelectableChipsComponent_li_2_i_5_Template, 1, 0, "i", 6);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(6, "span", 7);
    i0.ɵɵelementStart(7, "strong");
    i0.ɵɵtext(8);
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var option_r3 = ctx.$implicit;
    var i_r4 = ctx.index;
    var ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate(option_r3.title);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate1(" \u00A0", option_r3.subtitle, " ");
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", !ctx_r0.readonly);
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate1(" ", i_r4 === ctx_r0.andChips.length - 1 ? "" : option_r3.separator, " ");
} }
function AlSelectableChipsComponent_div_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 9);
    i0.ɵɵelementStart(1, "strong");
    i0.ɵɵtext(2, "OR");
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} }
function AlSelectableChipsComponent_li_5_i_5_Template(rf, ctx) { if (rf & 1) {
    var _r14 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "i", 8);
    i0.ɵɵlistener("click", function AlSelectableChipsComponent_li_5_i_5_Template_i_click_0_listener() { i0.ɵɵrestoreView(_r14); var i_r10 = i0.ɵɵnextContext().index; var ctx_r12 = i0.ɵɵnextContext(); return ctx_r12.removeSelectedItemAt(i_r10, "or"); });
    i0.ɵɵelementEnd();
} }
function AlSelectableChipsComponent_li_5_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "li", 4);
    i0.ɵɵelementStart(1, "span", 5);
    i0.ɵɵelementStart(2, "strong");
    i0.ɵɵtext(3);
    i0.ɵɵelementEnd();
    i0.ɵɵtext(4);
    i0.ɵɵtemplate(5, AlSelectableChipsComponent_li_5_i_5_Template, 1, 0, "i", 6);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(6, "span", 7);
    i0.ɵɵelementStart(7, "strong");
    i0.ɵɵtext(8);
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var option_r9 = ctx.$implicit;
    var i_r10 = ctx.index;
    var ctx_r2 = i0.ɵɵnextContext();
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate1(" ", option_r9.title, " ");
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate1(" \u00A0", option_r9.subtitle, " ");
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", !ctx_r2.readonly);
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate1(" ", i_r10 === ctx_r2.orChips.length - 1 ? "" : option_r9.separator, " ");
} }
var AlSelectableChipsComponent = /** @class */ (function () {
    function AlSelectableChipsComponent() {
        this.options = [];
        this.readonly = false;
        this.onSelectionChanged = new EventEmitter();
        this.orChips = [];
        this.andChips = [];
    }
    AlSelectableChipsComponent.prototype.ngOnChanges = function () {
        if (this.options) {
            this.splitOptions();
        }
    };
    AlSelectableChipsComponent.prototype.removeSelectedItemAt = function (index, list) {
        var element;
        if (list === 'and') {
            element = this.andChips[index];
        }
        else if (list === 'or') {
            element = this.orChips[index];
        }
        index = this.options.findIndex(function (opt) { return opt.id === element.id; });
        this.options.splice(index, 1);
        this.onSelectionChanged.emit(this.options);
        this.splitOptions();
    };
    AlSelectableChipsComponent.prototype.splitOptions = function () {
        var _this = this;
        this.orChips = [];
        this.andChips = [];
        this.options.forEach(function (opt) {
            var element = __assign({}, opt);
            if (opt.separator === 'AND' || opt.separator === 'and') {
                _this.andChips
                    .push(element);
            }
            else if (opt.separator === 'OR' || opt.separator === 'or') {
                _this.orChips
                    .push(element);
            }
        });
    };
    /** @nocollapse */ AlSelectableChipsComponent.ɵfac = function AlSelectableChipsComponent_Factory(t) { return new (t || AlSelectableChipsComponent)(); };
    /** @nocollapse */ AlSelectableChipsComponent.ɵcmp = i0.ɵɵdefineComponent({ type: AlSelectableChipsComponent, selectors: [["al-selectable-chips"]], inputs: { options: "options", readonly: "readonly" }, outputs: { onSelectionChanged: "onSelectionChanged" }, features: [i0.ɵɵNgOnChangesFeature], decls: 6, vars: 3, consts: [[1, "options-container"], [1, "chips"], ["class", "options", 4, "ngFor", "ngForOf"], ["class", "big-or", 4, "ngIf"], [1, "options"], [1, "chip"], ["style", "cursor: pointer; font-size:medium", "class", "pi pi-times", 3, "click", 4, "ngIf"], [1, "separator"], [1, "pi", "pi-times", 2, "cursor", "pointer", "font-size", "medium", 3, "click"], [1, "big-or"]], template: function AlSelectableChipsComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div", 0);
            i0.ɵɵelementStart(1, "ul", 1);
            i0.ɵɵtemplate(2, AlSelectableChipsComponent_li_2_Template, 9, 4, "li", 2);
            i0.ɵɵelementEnd();
            i0.ɵɵtemplate(3, AlSelectableChipsComponent_div_3_Template, 3, 0, "div", 3);
            i0.ɵɵelementStart(4, "ul", 1);
            i0.ɵɵtemplate(5, AlSelectableChipsComponent_li_5_Template, 9, 4, "li", 2);
            i0.ɵɵelementEnd();
            i0.ɵɵelementEnd();
        } if (rf & 2) {
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("ngForOf", ctx.andChips);
            i0.ɵɵadvance(1);
            i0.ɵɵproperty("ngIf", ctx.andChips.length > 0 && ctx.orChips.length > 0);
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("ngForOf", ctx.orChips);
        } }, directives: [i1.NgForOf, i1.NgIf], styles: [".options-container[_ngcontent-%COMP%]{max-height:50vh;overflow-y:scroll;overflow-x:scroll}.options-container[_ngcontent-%COMP%]   .chips[_ngcontent-%COMP%]{padding-top:10px;padding-bottom:10px;display:flex;flex-wrap:wrap;border-bottom:none}.options-container[_ngcontent-%COMP%]   .chips[_ngcontent-%COMP%]   .options[_ngcontent-%COMP%]{list-style-type:none}.options-container[_ngcontent-%COMP%]   .chips[_ngcontent-%COMP%]   .options[_ngcontent-%COMP%]   .chip[_ngcontent-%COMP%]{padding:4px;border-radius:1.5}.options-container[_ngcontent-%COMP%]   .chips[_ngcontent-%COMP%]   .options[_ngcontent-%COMP%]   .separator[_ngcontent-%COMP%]{color:#000;padding-right:7px}.options-container[_ngcontent-%COMP%]   .big-or[_ngcontent-%COMP%]{padding:40px;display:flex}"] });
    return AlSelectableChipsComponent;
}());
export { AlSelectableChipsComponent };
/*@__PURE__*/ (function () { i0.ɵsetClassMetadata(AlSelectableChipsComponent, [{
        type: Component,
        args: [{
                selector: 'al-selectable-chips',
                templateUrl: './al-selectable-chips.component.html',
                styleUrls: ['./al-selectable-chips.component.scss']
            }]
    }], null, { options: [{
            type: Input
        }], readonly: [{
            type: Input
        }], onSelectionChanged: [{
            type: Output
        }] }); })();
//# sourceMappingURL=data:application/json;base64, 