/**
 * An enhanced version of the primeng multiselect but with list.
 *
 * @author Gisler Garces <ggarces@alertlogic.com>
 * @author Fábio Miranda <fmiranda@alertlogic.com>
 * @copyright 2020 Alert Logic, Inc.
 */
import { Component, Input, Optional, Self } from '@angular/core';
import { NgControl } from '@angular/forms';
import * as i0 from "@angular/core";
import * as i1 from "@angular/forms";
import * as i2 from "primeng-lts/dropdown";
import * as i3 from "primeng-lts/api";
import * as i4 from "../al-selectable-list/al-selectable-list.component";
function AlDropdownListComponent_ng_template_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 4);
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate(ctx_r0.placeholder);
} }
function AlDropdownListComponent_ng_template_3_Template(rf, ctx) { if (rf & 1) {
    const _r5 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 5);
    i0.ɵɵlistener("click", function AlDropdownListComponent_ng_template_3_Template_div_click_0_listener() { i0.ɵɵrestoreView(_r5); const item_r3 = ctx.$implicit; const ctx_r4 = i0.ɵɵnextContext(); return ctx_r4.selectOption(item_r3); });
    i0.ɵɵelementStart(1, "div", 6);
    i0.ɵɵelementStart(2, "div", 7);
    i0.ɵɵtext(3);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(4, "div", 8);
    i0.ɵɵtext(5);
    i0.ɵɵelementStart(6, "i", 9);
    i0.ɵɵtext(7, "add_circle");
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const item_r3 = ctx.$implicit;
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate(item_r3.title);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", item_r3.subtitle, " ");
} }
export class AlDropdownListComponent {
    constructor(control) {
        this.control = control;
        // The default label placeholder to display on the dropdown selector
        this.placeholder = 'Choose';
        // The options to be displayed on the dropdown menu list
        this.options = [];
        // Read only mode for dropdown
        this.readonly = false;
        this.onChangeFn = (value) => {
            // empty intentional
        };
        this.onTouchFn = () => {
            // empty intentional
        };
        this.control && (this.control.valueAccessor = this);
    }
    /**
     * Function which triggers when an item is selected from the dropdown list
     * @param event The prime-ng event with the selected items and the last changed item
     **/
    selectOption(event) {
        const addedItem = event.value;
        if (!this.value) {
            this.value = [];
        }
        const index = this.value.indexOf(addedItem);
        if (index === -1) {
            this.value.push(addedItem);
        }
        this.onChangeFn(this.value);
    }
    writeValue(value) {
        if (value) {
            this.value = value || null;
        }
        else {
            this.value = null;
        }
    }
    registerOnChange(fn) {
        this.onChangeFn = fn;
    }
    registerOnTouched(fn) {
        this.onTouchFn = fn;
    }
    setDisabledState(isDisabled) {
        this.isDisabled = isDisabled;
    }
    get invalid() {
        return this.control ? !!this.control.invalid : false;
    }
}
/** @nocollapse */ AlDropdownListComponent.ɵfac = function AlDropdownListComponent_Factory(t) { return new (t || AlDropdownListComponent)(i0.ɵɵdirectiveInject(i1.NgControl, 10)); };
/** @nocollapse */ AlDropdownListComponent.ɵcmp = i0.ɵɵdefineComponent({ type: AlDropdownListComponent, selectors: [["al-dropdown-list"]], inputs: { placeholder: "placeholder", options: "options", readonly: "readonly" }, decls: 5, vars: 7, consts: [["itemSize", "30", "filterBy", "value.details,title,value.title,value.subtitle", 3, "placeholder", "options", "virtualScroll", "readonly", "filter", "onChange"], ["pTemplate", "selectedItem"], ["pTemplate", "item"], [3, "readonly", "options", "onSelectionChanged"], [1, "ui-dropdown-label", "ui-inputtext", "ui-corner-all", "ui-placeholder"], [1, "option-container-details", 3, "click"], [1, "option-inner-container"], [1, "option-title"], [1, "option-subtitle"], [1, "material-icons"]], template: function AlDropdownListComponent_Template(rf, ctx) { if (rf & 1) {
        i0.ɵɵelementStart(0, "p-dropdown", 0);
        i0.ɵɵlistener("onChange", function AlDropdownListComponent_Template_p_dropdown_onChange_0_listener($event) { return ctx.selectOption($event); });
        i0.ɵɵtext(1, " > ");
        i0.ɵɵtemplate(2, AlDropdownListComponent_ng_template_2_Template, 2, 1, "ng-template", 1);
        i0.ɵɵtemplate(3, AlDropdownListComponent_ng_template_3_Template, 8, 2, "ng-template", 2);
        i0.ɵɵelementEnd();
        i0.ɵɵelementStart(4, "al-selectable-list", 3);
        i0.ɵɵlistener("onSelectionChanged", function AlDropdownListComponent_Template_al_selectable_list_onSelectionChanged_4_listener($event) { return ctx.onChangeFn($event); });
        i0.ɵɵelementEnd();
    } if (rf & 2) {
        i0.ɵɵproperty("placeholder", ctx.placeholder)("options", ctx.options)("virtualScroll", true)("readonly", ctx.readonly)("filter", true);
        i0.ɵɵadvance(4);
        i0.ɵɵproperty("readonly", ctx.readonly)("options", ctx.value);
    } }, directives: [i2.Dropdown, i3.PrimeTemplate, i4.AlSelectableListComponent], styles: ["[_nghost-%COMP%]     .ui-dropdown .ui-dropdown-item-empty{text-indent:0}[_nghost-%COMP%]     .ui-dropdown .ui-dropdown-panel.ui-widget.ui-widget-content.ui-corner-all.ui-shadow{box-shadow:none;min-width:300px;width:100%;top:-5px}[_nghost-%COMP%]     .ui-dropdown .ui-dropdown-panel.ui-widget.ui-widget-content.ui-corner-all.ui-shadow .ui-dropdown-filter-container{color:#535353;background:#fff;border:none;padding:10px 0}[_nghost-%COMP%]     .ui-dropdown .ui-dropdown-panel.ui-widget.ui-widget-content.ui-corner-all.ui-shadow .ui-dropdown-filter-container input{color:#535353}[_nghost-%COMP%]     .ui-dropdown .ui-dropdown-panel.ui-widget.ui-widget-content.ui-corner-all.ui-shadow .ui-dropdown-filter-container .pi{color:#535353}[_nghost-%COMP%]     .ui-dropdown .ui-dropdown-panel.ui-widget.ui-widget-content.ui-corner-all.ui-shadow .ui-dropdown-items-wrapper{box-shadow:0 1px 3px 0 rgba(0,0,0,.3)}[_nghost-%COMP%]     .ui-dropdown .ui-dropdown-panel.ui-widget.ui-widget-content.ui-corner-all.ui-shadow .ui-dropdown-item.ui-state-highlight{background-color:#fff;color:#3c3c3c}[_nghost-%COMP%]     .ui-dropdown .ui-dropdown-panel.ui-widget.ui-widget-content.ui-corner-all.ui-shadow .ui-dropdown-item.ui-state-highlight:hover{background-color:#e8e8e8;color:#000}[_nghost-%COMP%]     .ui-dropdown .ui-dropdown-label.ui-inputtext{font-family:\"Open Sans\",Arial,sans-serif;color:var(--ald-g-color-text-primary)}[_nghost-%COMP%]     .ui-dropdown .option-container{margin-left:3px}[_nghost-%COMP%]     .ui-dropdown .option-inner-container{display:flex;justify-content:space-between}[_nghost-%COMP%]     .ui-dropdown .option-title{display:flex;font-weight:700}[_nghost-%COMP%]     .ui-dropdown .option-subtitle{display:flex;color:#a9a8a9}[_nghost-%COMP%]     .ui-dropdown .option-subtitle .material-icons{margin-left:10px;font-size:18px;color:#616261}"] });
/*@__PURE__*/ (function () { i0.ɵsetClassMetadata(AlDropdownListComponent, [{
        type: Component,
        args: [{
                selector: 'al-dropdown-list',
                templateUrl: './al-dropdown-list.component.html',
                styleUrls: ['./al-dropdown-list.component.scss']
            }]
    }], function () { return [{ type: i1.NgControl, decorators: [{
                type: Self
            }, {
                type: Optional
            }] }]; }, { placeholder: [{
            type: Input
        }], options: [{
            type: Input
        }], readonly: [{
            type: Input
        }] }); })();
//# sourceMappingURL=data:application/json;base64, 