import { Component, EventEmitter, Input, Output, ViewChild, ViewEncapsulation } from '@angular/core';
import { AlSearchBarComponent } from '../al-search-bar/al-search-bar.component';
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/multiselect";
import * as i5 from "primeng-lts/dropdown";
import * as i6 from "primeng-lts/api";
import * as i7 from "primeng-lts/tooltip";
import * as i8 from "../al-search-bar/al-search-bar.component";
const _c0 = ["alSearchBar"];
function AlContentToolbarComponent_div_2_Template(rf, ctx) { if (rf & 1) {
    const _r8 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 8);
    i0.ɵɵelementStart(1, "p-checkbox", 9);
    i0.ɵɵlistener("ngModelChange", function AlContentToolbarComponent_div_2_Template_p_checkbox_ngModelChange_1_listener($event) { i0.ɵɵrestoreView(_r8); const ctx_r7 = i0.ɵɵnextContext(); return ctx_r7.state.selectAll = $event; })("onChange", function AlContentToolbarComponent_div_2_Template_p_checkbox_onChange_1_listener() { i0.ɵɵrestoreView(_r8); const ctx_r9 = i0.ɵɵnextContext(); return ctx_r9.selectAllValues(); });
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngModel", ctx_r0.state.selectAll)("binary", true);
} }
function AlContentToolbarComponent_div_4_Template(rf, ctx) { if (rf & 1) {
    const _r11 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 10);
    i0.ɵɵelementStart(1, "p-multiSelect", 11);
    i0.ɵɵlistener("ngModelChange", function AlContentToolbarComponent_div_4_Template_p_multiSelect_ngModelChange_1_listener($event) { i0.ɵɵrestoreView(_r11); const ctx_r10 = i0.ɵɵnextContext(); return ctx_r10.state.filters.selectedOptions = $event; })("onChange", function AlContentToolbarComponent_div_4_Template_p_multiSelect_onChange_1_listener() { i0.ɵɵrestoreView(_r11); const ctx_r12 = i0.ɵɵnextContext(); return ctx_r12.handleFilterSelection(); });
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("options", ctx_r1.state.filters.options)("ngModel", ctx_r1.state.filters.selectedOptions)("defaultLabel", ctx_r1.state.filters.label);
} }
function AlContentToolbarComponent_div_5_ng_template_2_i_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "i", 18);
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const item_r15 = i0.ɵɵnextContext().$implicit;
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate(item_r15.icon == null ? null : item_r15.icon.name);
} }
function AlContentToolbarComponent_div_5_ng_template_2_i_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "i");
} if (rf & 2) {
    const item_r15 = i0.ɵɵnextContext().$implicit;
    i0.ɵɵclassMapInterpolate1(" c-icon-sm ", item_r15.icon == null ? null : item_r15.icon.cssClasses, "");
} }
function AlContentToolbarComponent_div_5_ng_template_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 1);
    i0.ɵɵtemplate(1, AlContentToolbarComponent_div_5_ng_template_2_i_1_Template, 2, 1, "i", 15);
    i0.ɵɵtemplate(2, AlContentToolbarComponent_div_5_ng_template_2_i_2_Template, 1, 3, "i", 16);
    i0.ɵɵelementStart(3, "span", 17);
    i0.ɵɵtext(4);
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const item_r15 = ctx.$implicit;
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", item_r15.icon == null ? null : item_r15.icon.name);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", item_r15.icon == null ? null : item_r15.icon.cssClasses);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(item_r15.label);
} }
function AlContentToolbarComponent_div_5_ng_template_3_i_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "i", 18);
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const view_r20 = i0.ɵɵnextContext().$implicit;
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate(view_r20.icon == null ? null : view_r20.icon.name);
} }
function AlContentToolbarComponent_div_5_ng_template_3_i_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "i");
} if (rf & 2) {
    const view_r20 = i0.ɵɵnextContext().$implicit;
    i0.ɵɵclassMapInterpolate1("c-icon-sm ", view_r20.icon == null ? null : view_r20.icon.cssClasses, "");
} }
function AlContentToolbarComponent_div_5_ng_template_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 19);
    i0.ɵɵtemplate(1, AlContentToolbarComponent_div_5_ng_template_3_i_1_Template, 2, 1, "i", 15);
    i0.ɵɵtemplate(2, AlContentToolbarComponent_div_5_ng_template_3_i_2_Template, 1, 3, "i", 16);
    i0.ɵɵelementStart(3, "div", 17);
    i0.ɵɵtext(4);
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const view_r20 = ctx.$implicit;
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", view_r20.icon == null ? null : view_r20.icon.name);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", view_r20.icon == null ? null : view_r20.icon.cssClasses);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(view_r20.label);
} }
function AlContentToolbarComponent_div_5_Template(rf, ctx) { if (rf & 1) {
    const _r26 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div");
    i0.ɵɵelementStart(1, "p-dropdown", 12);
    i0.ɵɵlistener("ngModelChange", function AlContentToolbarComponent_div_5_Template_p_dropdown_ngModelChange_1_listener($event) { i0.ɵɵrestoreView(_r26); const ctx_r25 = i0.ɵɵnextContext(); return ctx_r25.state.viewSelected = $event; })("onChange", function AlContentToolbarComponent_div_5_Template_p_dropdown_onChange_1_listener() { i0.ɵɵrestoreView(_r26); const ctx_r27 = i0.ɵɵnextContext(); return ctx_r27.handleViewSelection(); });
    i0.ɵɵtemplate(2, AlContentToolbarComponent_div_5_ng_template_2_Template, 5, 3, "ng-template", 13);
    i0.ɵɵtemplate(3, AlContentToolbarComponent_div_5_ng_template_3_Template, 5, 3, "ng-template", 14);
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r2 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("options", ctx_r2.state.viewBy)("ngModel", ctx_r2.state.viewSelected)("scrollHeight", "unset");
} }
function AlContentToolbarComponent_p_dropdown_6_Template(rf, ctx) { if (rf & 1) {
    const _r29 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "p-dropdown", 20);
    i0.ɵɵlistener("ngModelChange", function AlContentToolbarComponent_p_dropdown_6_Template_p_dropdown_ngModelChange_0_listener($event) { i0.ɵɵrestoreView(_r29); const ctx_r28 = i0.ɵɵnextContext(); return ctx_r28.state.group.selectedOption = $event; })("onChange", function AlContentToolbarComponent_p_dropdown_6_Template_p_dropdown_onChange_0_listener() { i0.ɵɵrestoreView(_r29); const ctx_r30 = i0.ɵɵnextContext(); return ctx_r30.handleGroupSelection(); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r3 = i0.ɵɵnextContext();
    i0.ɵɵproperty("options", ctx_r3.state.group.options)("ngModel", ctx_r3.state.group.selectedOption);
} }
function AlContentToolbarComponent_p_dropdown_7_Template(rf, ctx) { if (rf & 1) {
    const _r32 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "p-dropdown", 21);
    i0.ɵɵlistener("ngModelChange", function AlContentToolbarComponent_p_dropdown_7_Template_p_dropdown_ngModelChange_0_listener($event) { i0.ɵɵrestoreView(_r32); const ctx_r31 = i0.ɵɵnextContext(); return ctx_r31.state.sort.selectedOption = $event; })("onChange", function AlContentToolbarComponent_p_dropdown_7_Template_p_dropdown_onChange_0_listener() { i0.ɵɵrestoreView(_r32); const ctx_r33 = i0.ɵɵnextContext(); return ctx_r33.handleSortSelection(); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r4 = i0.ɵɵnextContext();
    i0.ɵɵproperty("options", ctx_r4.state.sort.options)("ngModel", ctx_r4.state.sort.selectedOption);
} }
function AlContentToolbarComponent_i_8_Template(rf, ctx) { if (rf & 1) {
    const _r35 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "i", 22);
    i0.ɵɵlistener("click", function AlContentToolbarComponent_i_8_Template_i_click_0_listener() { i0.ɵɵrestoreView(_r35); const ctx_r34 = i0.ɵɵnextContext(); return ctx_r34.sort(); });
    i0.ɵɵtext(1, " swap_vert ");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r5 = i0.ɵɵnextContext();
    i0.ɵɵproperty("pTooltip", ctx_r5.state.sort.order === "asc" ? "ascending" : "descending");
} }
function AlContentToolbarComponent_div_9_Template(rf, ctx) { if (rf & 1) {
    const _r38 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div");
    i0.ɵɵelementStart(1, "al-search-bar", 23, 24);
    i0.ɵɵlistener("onSearchChanged", function AlContentToolbarComponent_div_9_Template_al_search_bar_onSearchChanged_1_listener($event) { i0.ɵɵrestoreView(_r38); const ctx_r37 = i0.ɵɵnextContext(); return ctx_r37.applyTextFilter($event); });
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r6 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("placeholder", ctx_r6.state.search.textPlaceHolder)("maxSearchLength", ctx_r6.state.search.maxSearchLength);
} }
export class AlContentToolbarComponent {
    constructor() {
        this.onOrderBy = new EventEmitter();
        this.onSearched = new EventEmitter();
        this.onFiltersSelection = new EventEmitter();
        this.onSortSelection = new EventEmitter();
        this.onGroupSelection = new EventEmitter();
        this.onSelectAll = new EventEmitter();
        this.onViewSelection = new EventEmitter();
        this.state = {
            showSelectAll: false,
            selectAll: false,
            showFilters: false,
            filters: {
                label: "Select any filter(s)",
                options: [],
                selectedOptions: []
            },
            showSortBy: false,
            sort: {
                options: [],
                selectedOption: '',
                order: 'asc'
            },
            showGroupBy: false,
            group: {
                options: [],
                selectedOption: ''
            },
            showSearch: true,
            search: {
                maxSearchLength: 0,
                textPlaceHolder: ''
            },
            showViewBy: false,
            viewBy: [],
            viewSelected: ''
        };
    }
    ngOnChanges(changes) {
        if (changes.hasOwnProperty('config')) {
            Object.assign(this.state, this.config);
            if (this.state.viewBy && this.state.viewBy.length) {
                this.state.viewBy.forEach(viewDef => {
                    if (viewDef.default) {
                        this.state.viewSelected = viewDef.value;
                    }
                });
            }
        }
    }
    selectAllValues() {
        this.onSelectAll.emit(this.state.selectAll);
    }
    sort() {
        this.state.sort.order = this.state.sort.order === 'asc' ? 'desc' : 'asc';
        this.onOrderBy.emit(this.state.sort.order);
    }
    handleFilterSelection() {
        if (this.state.filters.selectedOptions) {
            this.onFiltersSelection.emit(this.state.filters.selectedOptions);
        }
    }
    handleSortSelection() {
        if (this.state.sort.selectedOption) {
            this.onSortSelection.emit(this.state.sort.selectedOption);
        }
    }
    handleGroupSelection() {
        if (this.state.group.selectedOption) {
            this.onGroupSelection.emit(this.state.group.selectedOption);
        }
    }
    handleViewSelection() {
        if (this.state.viewSelected) {
            this.onViewSelection.emit(this.state.viewSelected);
        }
    }
    /**
      * Emit the event search
      */
    applyTextFilter(searchInput) {
        this.onSearched.emit(searchInput);
    }
    setTextFilter(searchInput) {
        this.alSearchBar.searchControl.setValue(searchInput);
    }
    uncheckAllOption() {
        this.state.selectAll = false;
    }
}
/** @nocollapse */ AlContentToolbarComponent.ɵfac = function AlContentToolbarComponent_Factory(t) { return new (t || AlContentToolbarComponent)(); };
/** @nocollapse */ AlContentToolbarComponent.ɵcmp = i0.ɵɵdefineComponent({ type: AlContentToolbarComponent, selectors: [["al-content-toolbar"]], viewQuery: function AlContentToolbarComponent_Query(rf, ctx) { if (rf & 1) {
        i0.ɵɵviewQuery(_c0, true);
    } if (rf & 2) {
        var _t;
        i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.alSearchBar = _t.first);
    } }, inputs: { config: "config" }, outputs: { onOrderBy: "onOrderBy", onSearched: "onSearched", onFiltersSelection: "onFiltersSelection", onSortSelection: "onSortSelection", onGroupSelection: "onGroupSelection", onSelectAll: "onSelectAll", onViewSelection: "onViewSelection" }, features: [i0.ɵɵNgOnChangesFeature], decls: 10, vars: 7, consts: [[1, "u-flex", "u-justify-between", "u-items-center", "u-mb-2"], [1, "u-flex", "u-items-center"], ["class", "u-flex-grow-0 u-flex-shrink-0 u-w-18", 4, "ngIf"], ["class", "u-col u-col-fixed u-self-end filters", 4, "ngIf"], [4, "ngIf"], ["class", "u-ml-4", "data-cy", "content-toolbar-groupby", 3, "options", "ngModel", "ngModelChange", "onChange", 4, "ngIf"], ["class", "u-ml-4", "data-cy", "content-toolbar-sort", "data-cy", "content-toolbar-sort", 3, "options", "ngModel", "ngModelChange", "onChange", 4, "ngIf"], ["class", "material-icons u-mx-4 u-my-0 u-cursor-pointer", 3, "pTooltip", "click", 4, "ngIf"], [1, "u-flex-grow-0", "u-flex-shrink-0", "u-w-18"], [1, "u-flex", "u-justify-center", "u-h-100%", "u-mr-0", 3, "ngModel", "binary", "ngModelChange", "onChange"], [1, "u-col", "u-col-fixed", "u-self-end", "filters"], ["selectedItemsLabel", "{0} filter(s) selected", 1, "u-mr-4", 3, "options", "ngModel", "defaultLabel", "ngModelChange", "onChange"], ["data-cy", "content-toolbar-viewBy", 3, "options", "ngModel", "scrollHeight", "ngModelChange", "onChange"], ["pTemplate", "selectedItem"], ["pTemplate", "item"], ["class", "material-icons c-icon-sm", 4, "ngIf"], [3, "class", 4, "ngIf"], [1, "u-text-sm", "u-ml-2"], [1, "material-icons", "c-icon-sm"], ["data-cy", "content-toolbar-viewBy-option", 1, "u-flex", "u-items-center"], ["data-cy", "content-toolbar-groupby", 1, "u-ml-4", 3, "options", "ngModel", "ngModelChange", "onChange"], ["data-cy", "content-toolbar-sort", "data-cy", "content-toolbar-sort", 1, "u-ml-4", 3, "options", "ngModel", "ngModelChange", "onChange"], [1, "material-icons", "u-mx-4", "u-my-0", "u-cursor-pointer", 3, "pTooltip", "click"], [3, "placeholder", "maxSearchLength", "onSearchChanged"], ["alSearchBar", ""]], template: function AlContentToolbarComponent_Template(rf, ctx) { if (rf & 1) {
        i0.ɵɵelementStart(0, "div", 0);
        i0.ɵɵelementStart(1, "div", 1);
        i0.ɵɵtemplate(2, AlContentToolbarComponent_div_2_Template, 2, 2, "div", 2);
        i0.ɵɵelementStart(3, "div", 1);
        i0.ɵɵtemplate(4, AlContentToolbarComponent_div_4_Template, 2, 3, "div", 3);
        i0.ɵɵtemplate(5, AlContentToolbarComponent_div_5_Template, 4, 3, "div", 4);
        i0.ɵɵtemplate(6, AlContentToolbarComponent_p_dropdown_6_Template, 1, 2, "p-dropdown", 5);
        i0.ɵɵtemplate(7, AlContentToolbarComponent_p_dropdown_7_Template, 1, 2, "p-dropdown", 6);
        i0.ɵɵtemplate(8, AlContentToolbarComponent_i_8_Template, 2, 1, "i", 7);
        i0.ɵɵelementEnd();
        i0.ɵɵelementEnd();
        i0.ɵɵtemplate(9, AlContentToolbarComponent_div_9_Template, 3, 2, "div", 4);
        i0.ɵɵelementEnd();
    } if (rf & 2) {
        i0.ɵɵadvance(2);
        i0.ɵɵproperty("ngIf", ctx.state.showSelectAll);
        i0.ɵɵadvance(2);
        i0.ɵɵproperty("ngIf", ctx.state.showFilters && (ctx.state.filters.options == null ? null : ctx.state.filters.options.length) > 0);
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngIf", ctx.state.showViewBy && (ctx.state.viewBy == null ? null : ctx.state.viewBy.length) > 0);
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngIf", ctx.state.showGroupBy && (ctx.state.group.options == null ? null : ctx.state.group.options.length) > 0);
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngIf", ctx.state.showSortBy && (ctx.state.sort.options == null ? null : ctx.state.sort.options.length) > 0);
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngIf", ctx.state.showSortBy);
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngIf", ctx.state.showSearch);
    } }, directives: [i1.NgIf, i2.Checkbox, i3.NgControlStatus, i3.NgModel, i4.MultiSelect, i5.Dropdown, i6.PrimeTemplate, i7.Tooltip, i8.AlSearchBarComponent], styles: ["al-content-toolbar .filters{padding-left:0}al-content-toolbar p-multiSelect .ui-multiselect{width:240px}"], encapsulation: 2 });
/*@__PURE__*/ (function () { i0.ɵsetClassMetadata(AlContentToolbarComponent, [{
        type: Component,
        args: [{
                selector: 'al-content-toolbar',
                templateUrl: './al-content-toolbar.component.html',
                styleUrls: ['./al-content-toolbar.component.scss'],
                encapsulation: ViewEncapsulation.None
            }]
    }], null, { config: [{
            type: Input
        }], onOrderBy: [{
            type: Output
        }], onSearched: [{
            type: Output
        }], onFiltersSelection: [{
            type: Output
        }], onSortSelection: [{
            type: Output
        }], onGroupSelection: [{
            type: Output
        }], onSelectAll: [{
            type: Output
        }], onViewSelection: [{
            type: Output
        }], alSearchBar: [{
            type: ViewChild,
            args: ['alSearchBar']
        }] }); })();
//# sourceMappingURL=data:application/json;base64, 