import { Component, Input, Output, EventEmitter, ViewEncapsulation, ViewChild } from '@angular/core';
import { Calendar } from 'primeng-lts/calendar';
import { AlDateRangeSelectorComponent } from '../al-date-range-selector/al-date-range-selector.component';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "primeng-lts/tooltip";
import * as i3 from "primeng-lts/button";
import * as i4 from "primeng-lts/calendar";
import * as i5 from "@angular/forms";
import * as i6 from "primeng-lts/api";
import * as i7 from "../al-date-range-selector/al-date-range-selector.component";
var _c0 = ["datePicker"];
var _c1 = ["alDateSelector"];
function AlContentHeaderComponent_div_1_Template(rf, ctx) { if (rf & 1) {
    var _r6 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div");
    i0.ɵɵelementStart(1, "div", 10);
    i0.ɵɵelementStart(2, "button", 11);
    i0.ɵɵlistener("click", function AlContentHeaderComponent_div_1_Template_button_click_2_listener($event) { i0.ɵɵrestoreView(_r6); var ctx_r5 = i0.ɵɵnextContext(); return ctx_r5.onClickAddButton($event); });
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("pTooltip", ctx_r0.addButtonTooltip);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("disabled", ctx_r0.disableAddButton);
} }
function AlContentHeaderComponent_i_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "i", 12);
} if (rf & 2) {
    var ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵclassMap(ctx_r1.icon);
} }
function AlContentHeaderComponent_i_5_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "i", 13);
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var ctx_r2 = i0.ɵɵnextContext();
    i0.ɵɵproperty("ngClass", ctx_r2.iconConfig == null ? null : ctx_r2.iconConfig.cssClasses);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate1(" ", ctx_r2.iconConfig == null ? null : ctx_r2.iconConfig.name, " ");
} }
function AlContentHeaderComponent_div_9_p_calendar_1_Template(rf, ctx) { if (rf & 1) {
    var _r12 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "p-calendar", 17, 18);
    i0.ɵɵlistener("ngModelChange", function AlContentHeaderComponent_div_9_p_calendar_1_Template_p_calendar_ngModelChange_0_listener($event) { i0.ɵɵrestoreView(_r12); var ctx_r11 = i0.ɵɵnextContext(2); return ctx_r11.dateRange = $event; })("onFocus", function AlContentHeaderComponent_div_9_p_calendar_1_Template_p_calendar_onFocus_0_listener() { i0.ɵɵrestoreView(_r12); var ctx_r13 = i0.ɵɵnextContext(2); return ctx_r13.toggleSelectorVisibility(); })("onClose", function AlContentHeaderComponent_div_9_p_calendar_1_Template_p_calendar_onClose_0_listener() { i0.ɵɵrestoreView(_r12); var ctx_r14 = i0.ɵɵnextContext(2); return ctx_r14.toggleSelectorVisibility(); })("onSelect", function AlContentHeaderComponent_div_9_p_calendar_1_Template_p_calendar_onSelect_0_listener() { i0.ɵɵrestoreView(_r12); var ctx_r15 = i0.ɵɵnextContext(2); return ctx_r15.selectedSingleDate(); });
    i0.ɵɵelementStart(2, "p-footer");
    i0.ɵɵelementStart(3, "div", 19);
    i0.ɵɵelementStart(4, "button", 20);
    i0.ɵɵlistener("click", function AlContentHeaderComponent_div_9_p_calendar_1_Template_button_click_4_listener() { i0.ɵɵrestoreView(_r12); var ctx_r16 = i0.ɵɵnextContext(2); return ctx_r16.close(); });
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(5, "button", 21);
    i0.ɵɵlistener("click", function AlContentHeaderComponent_div_9_p_calendar_1_Template_button_click_5_listener() { i0.ɵɵrestoreView(_r12); var ctx_r17 = i0.ɵɵnextContext(2); return ctx_r17.selectedDateRange(); });
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var ctx_r7 = i0.ɵɵnextContext(2);
    i0.ɵɵpropertyInterpolate("selectionMode", ctx_r7.showCalendar);
    i0.ɵɵproperty("ngModel", ctx_r7.dateRange)("placeholder", ctx_r7.dateTimePlaceholder)("showIcon", true)("icon", ctx_r7.showDateSelector ? "pi pi-chevron-up" : "pi pi-chevron-down")("showTime", ctx_r7.showTime);
} }
function AlContentHeaderComponent_div_9_span_2_i_1_Template(rf, ctx) { if (rf & 1) {
    var _r20 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "i", 23);
    i0.ɵɵlistener("click", function AlContentHeaderComponent_div_9_span_2_i_1_Template_i_click_0_listener() { i0.ɵɵrestoreView(_r20); var ctx_r19 = i0.ɵɵnextContext(3); return ctx_r19.clear(); });
    i0.ɵɵtext(1, "close");
    i0.ɵɵelementEnd();
} }
function AlContentHeaderComponent_div_9_span_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span");
    i0.ɵɵtemplate(1, AlContentHeaderComponent_div_9_span_2_i_1_Template, 2, 0, "i", 22);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var ctx_r8 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r8.dateRange);
} }
function AlContentHeaderComponent_div_9_al_date_range_selector_3_Template(rf, ctx) { if (rf & 1) {
    var _r23 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "al-date-range-selector", 24, 25);
    i0.ɵɵlistener("onDateSelected", function AlContentHeaderComponent_div_9_al_date_range_selector_3_Template_al_date_range_selector_onDateSelected_0_listener($event) { i0.ɵɵrestoreView(_r23); var ctx_r22 = i0.ɵɵnextContext(2); return ctx_r22.dateRangeSelectedFromAlDateRangeSelector($event); })("onClosedCalendar", function AlContentHeaderComponent_div_9_al_date_range_selector_3_Template_al_date_range_selector_onClosedCalendar_0_listener($event) { i0.ɵɵrestoreView(_r23); var ctx_r24 = i0.ɵɵnextContext(2); return ctx_r24.closedAlDateRangeSelector($event); })("onShowCalendar", function AlContentHeaderComponent_div_9_al_date_range_selector_3_Template_al_date_range_selector_onShowCalendar_0_listener($event) { i0.ɵɵrestoreView(_r23); var ctx_r25 = i0.ɵɵnextContext(2); return ctx_r25.showAlDateRangeSelector($event); })("onSelectFixedRange", function AlContentHeaderComponent_div_9_al_date_range_selector_3_Template_al_date_range_selector_onSelectFixedRange_0_listener($event) { i0.ɵɵrestoreView(_r23); var ctx_r26 = i0.ɵɵnextContext(2); return ctx_r26.selectFixedRangeAlDateRangeSelector($event); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var ctx_r9 = i0.ɵɵnextContext(2);
    i0.ɵɵproperty("initialDateRangeSelection", ctx_r9.initialDateRangeSelection)("fixedRanges", ctx_r9.defaultFixedRanges)("showTimePicker", ctx_r9.showTimePicker)("returnTimeFrame", ctx_r9.returnTimeFrame)("placeholder", ctx_r9.placeholder)("selectorTitle", ctx_r9.selectorTitle)("customRangeTitle", ctx_r9.customRangeTitle)("calendarMaxDate", ctx_r9.calendarMaxDate)("calendarMinDate", ctx_r9.calendarMinDate);
} }
function AlContentHeaderComponent_div_9_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 14);
    i0.ɵɵtemplate(1, AlContentHeaderComponent_div_9_p_calendar_1_Template, 6, 6, "p-calendar", 15);
    i0.ɵɵtemplate(2, AlContentHeaderComponent_div_9_span_2_Template, 2, 1, "span", 1);
    i0.ɵɵtemplate(3, AlContentHeaderComponent_div_9_al_date_range_selector_3_Template, 2, 9, "al-date-range-selector", 16);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var ctx_r3 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r3.showCalendar !== "al-date-range-selector");
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r3.dateRange && ctx_r3.showCalendar !== "al-date-range-selector");
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r3.showCalendar === "al-date-range-selector");
} }
function AlContentHeaderComponent_div_10_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "div", 26);
} if (rf & 2) {
    var ctx_r4 = i0.ɵɵnextContext();
    i0.ɵɵproperty("innerHTML", ctx_r4.descriptionHeader, i0.ɵɵsanitizeHtml);
} }
var AlContentHeaderComponent = /** @class */ (function () {
    function AlContentHeaderComponent() {
        /**
        *  Contains the css class to show icon
        */
        this.icon = "";
        this.iconConfig = null;
        /**
         *  Main title in the header
         */
        this.title = "";
        this.descriptionHeader = "";
        /**
         *  Absence of this property indicates the + button will not display.
         */
        this.showAddButton = false;
        this.disableAddButton = false;
        this.addButtonTooltip = "";
        this.addMenuItems = [];
        this.defaultDate = null;
        this.showTime = false;
        this.returnTimeFrame = false;
        this.showTimePicker = true;
        this.selectorTitle = 'Data for the last:';
        this.customRangeTitle = 'Custom range:';
        this.calendarMaxDaysHistory = 90; // By default we will be allowing the user to select 90 days in the past tops
        this.calendarMaxDate = new Date();
        this.calendarMinDate = new Date(new Date().setDate(this.calendarMaxDate.getDate() - this.calendarMaxDaysHistory));
        this.initialDateRangeSelection = undefined;
        this.onDateRangeSelectedFromAlDateRangeSelector = new EventEmitter();
        this.onClosedAlDateRangeSelector = new EventEmitter();
        this.onShowAlDateRangeSelector = new EventEmitter();
        this.onSelectFixedRangeAlDateRangeSelector = new EventEmitter();
        this.onDateRangeSelected = new EventEmitter();
        this.onButtonClicked = new EventEmitter();
        this.previousState = [];
    }
    AlContentHeaderComponent.prototype.ngOnChanges = function (changes) {
        if (changes && this.defaultDate) {
            this.dateRange = this.defaultDate;
            this.previousState = this.defaultDate;
        }
    };
    /**
    *  @method toggleSelectorVisibility
    *
    *  Toggles the Date Selector visibility
    */
    AlContentHeaderComponent.prototype.toggleSelectorVisibility = function () {
        this.showDateSelector = !this.showDateSelector;
    };
    AlContentHeaderComponent.prototype.selectedDateRange = function () {
        if (this.dateRange.length > 1 && this.dateRange[1]) {
            var endTime = this.dateRange[1];
            if (!this.showTime) {
                endTime.setHours(23);
                endTime.setMinutes(59);
                endTime.setSeconds(59);
            }
            this.dateRange[1] = endTime;
        }
        this.onDateRangeSelected.emit(this.dateRange);
        this.datePicker.overlayVisible = false;
        this.previousState = this.dateRange;
    };
    AlContentHeaderComponent.prototype.selectedSingleDate = function () {
        if (this.showCalendar && this.showCalendar === 'single') {
            this.onDateRangeSelected.emit(this.dateRange);
        }
    };
    AlContentHeaderComponent.prototype.onClickAddButton = function (event) {
        this.onButtonClicked.emit({ event: event });
    };
    AlContentHeaderComponent.prototype.dateRangeSelectedFromAlDateRangeSelector = function (event) {
        this.onDateRangeSelectedFromAlDateRangeSelector.emit(event);
    };
    AlContentHeaderComponent.prototype.closedAlDateRangeSelector = function (event) {
        this.onClosedAlDateRangeSelector.emit(event);
    };
    AlContentHeaderComponent.prototype.showAlDateRangeSelector = function (event) {
        this.onShowAlDateRangeSelector.emit(event);
    };
    AlContentHeaderComponent.prototype.selectFixedRangeAlDateRangeSelector = function (event) {
        this.onSelectFixedRangeAlDateRangeSelector.emit(event);
    };
    /**
     * close the calender on click of cancel
     */
    AlContentHeaderComponent.prototype.close = function () {
        if (this.previousState) {
            this.dateRange = this.previousState;
        }
        else {
            this.datePicker.onClearButtonClick(true);
        }
        this.datePicker.overlayVisible = false;
    };
    /**
    * reset the calender on click of clear
    */
    AlContentHeaderComponent.prototype.clear = function () {
        this.datePicker.onClearButtonClick(true);
        this.previousState = this.dateRange;
        this.onDateRangeSelected.emit(this.dateRange);
    };
    AlContentHeaderComponent.prototype.setDateRange = function (dateRange, emit) {
        var _this = this;
        if (emit === void 0) { emit = true; }
        setTimeout(function () {
            if (_this.alDateSelector) {
                _this.alDateSelector.setupFromDateRange(dateRange, emit);
            }
        });
    };
    /** @nocollapse */ AlContentHeaderComponent.ɵfac = function AlContentHeaderComponent_Factory(t) { return new (t || AlContentHeaderComponent)(); };
    /** @nocollapse */ AlContentHeaderComponent.ɵcmp = i0.ɵɵdefineComponent({ type: AlContentHeaderComponent, selectors: [["al-content-header"]], viewQuery: function AlContentHeaderComponent_Query(rf, ctx) { if (rf & 1) {
            i0.ɵɵviewQuery(_c0, true);
            i0.ɵɵviewQuery(_c1, true);
        } if (rf & 2) {
            var _t;
            i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.datePicker = _t.first);
            i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.alDateSelector = _t.first);
        } }, inputs: { icon: "icon", iconConfig: "iconConfig", title: "title", descriptionHeader: "descriptionHeader", showAddButton: "showAddButton", disableAddButton: "disableAddButton", addButtonTooltip: "addButtonTooltip", addMenuItems: "addMenuItems", defaultDate: "defaultDate", showCalendar: "showCalendar", showTime: "showTime", dateTimePlaceholder: "dateTimePlaceholder", defaultFixedRanges: "defaultFixedRanges", returnTimeFrame: "returnTimeFrame", showTimePicker: "showTimePicker", placeholder: "placeholder", selectorTitle: "selectorTitle", customRangeTitle: "customRangeTitle", calendarMaxDaysHistory: "calendarMaxDaysHistory", calendarMaxDate: "calendarMaxDate", calendarMinDate: "calendarMinDate", initialDateRangeSelection: "initialDateRangeSelection" }, outputs: { onDateRangeSelectedFromAlDateRangeSelector: "onDateRangeSelectedFromAlDateRangeSelector", onClosedAlDateRangeSelector: "onClosedAlDateRangeSelector", onShowAlDateRangeSelector: "onShowAlDateRangeSelector", onSelectFixedRangeAlDateRangeSelector: "onSelectFixedRangeAlDateRangeSelector", onDateRangeSelected: "onDateRangeSelected", onButtonClicked: "onButtonClicked" }, features: [i0.ɵɵNgOnChangesFeature], decls: 11, vars: 6, consts: [[1, "u-flex", "u-items-center", "u-mt-3", "u-mb-2"], [4, "ngIf"], [1, "u-flex", "u-justify-between", "u-flex-1", "u-flex-wrap", "u-pb-2", "u-border-b", "u-border-solid", "u-border-primary"], [1, "u-flex", "u-items-center"], ["aria-hidden", "true", "class", "u-text-xxxl u-mr-2", 3, "class", 4, "ngIf"], ["class", "u-txt-xxxl u-mr-2", 3, "ngClass", 4, "ngIf"], ["data-cy", "content-header-title", 1, "u-flex-nowrap", "u-overflow-hidden", "u-text-xxxl", "u-font-medium", "u-overflow-ellipsis"], [1, "u-flex-grow-1", "u-flex-shrink-0"], ["class", "al-calender u-flex u-justify-end", 4, "ngIf"], ["class", "u-text-sm", 3, "innerHTML", 4, "ngIf"], [1, "u-mr-2", 3, "pTooltip"], ["pButton", "", "type", "button", "icon", "ui-icon-add", 1, "fab", "primaryAction", 3, "disabled", "click"], ["aria-hidden", "true", 1, "u-text-xxxl", "u-mr-2"], [1, "u-txt-xxxl", "u-mr-2", 3, "ngClass"], [1, "al-calender", "u-flex", "u-justify-end"], ["dateFormat", "d M yy", "hourFormat", "24", 3, "selectionMode", "ngModel", "placeholder", "showIcon", "icon", "showTime", "ngModelChange", "onFocus", "onClose", "onSelect", 4, "ngIf"], [3, "initialDateRangeSelection", "fixedRanges", "showTimePicker", "returnTimeFrame", "placeholder", "selectorTitle", "customRangeTitle", "calendarMaxDate", "calendarMinDate", "onDateSelected", "onClosedCalendar", "onShowCalendar", "onSelectFixedRange", 4, "ngIf"], ["dateFormat", "d M yy", "hourFormat", "24", 3, "selectionMode", "ngModel", "placeholder", "showIcon", "icon", "showTime", "ngModelChange", "onFocus", "onClose", "onSelect"], ["datePicker", ""], [1, "btnGroupRight"], ["pButton", "", "type", "button", "label", "Cancel", 1, "btnSmall", "flat", 3, "click"], ["pButton", "", "type", "button", "label", "Apply", 1, "btnSmall", "primaryAction", 3, "click"], ["class", "material-icons", 3, "click", 4, "ngIf"], [1, "material-icons", 3, "click"], [3, "initialDateRangeSelection", "fixedRanges", "showTimePicker", "returnTimeFrame", "placeholder", "selectorTitle", "customRangeTitle", "calendarMaxDate", "calendarMinDate", "onDateSelected", "onClosedCalendar", "onShowCalendar", "onSelectFixedRange"], ["alDateSelector", ""], [1, "u-text-sm", 3, "innerHTML"]], template: function AlContentHeaderComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div", 0);
            i0.ɵɵtemplate(1, AlContentHeaderComponent_div_1_Template, 3, 2, "div", 1);
            i0.ɵɵelementStart(2, "div", 2);
            i0.ɵɵelementStart(3, "div", 3);
            i0.ɵɵtemplate(4, AlContentHeaderComponent_i_4_Template, 1, 2, "i", 4);
            i0.ɵɵtemplate(5, AlContentHeaderComponent_i_5_Template, 2, 2, "i", 5);
            i0.ɵɵelementStart(6, "span", 6);
            i0.ɵɵtext(7);
            i0.ɵɵelementEnd();
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(8, "div", 7);
            i0.ɵɵtemplate(9, AlContentHeaderComponent_div_9_Template, 4, 3, "div", 8);
            i0.ɵɵelementEnd();
            i0.ɵɵelementEnd();
            i0.ɵɵelementEnd();
            i0.ɵɵtemplate(10, AlContentHeaderComponent_div_10_Template, 1, 1, "div", 9);
        } if (rf & 2) {
            i0.ɵɵadvance(1);
            i0.ɵɵproperty("ngIf", ctx.showAddButton);
            i0.ɵɵadvance(3);
            i0.ɵɵproperty("ngIf", ctx.icon);
            i0.ɵɵadvance(1);
            i0.ɵɵproperty("ngIf", ctx.iconConfig);
            i0.ɵɵadvance(2);
            i0.ɵɵtextInterpolate(ctx.title);
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("ngIf", !!ctx.showCalendar);
            i0.ɵɵadvance(1);
            i0.ɵɵproperty("ngIf", ctx.descriptionHeader);
        } }, directives: [i1.NgIf, i2.Tooltip, i3.ButtonDirective, i1.NgClass, i4.Calendar, i5.NgControlStatus, i5.NgModel, i6.Footer, i7.AlDateRangeSelectorComponent], styles: [""], encapsulation: 2 });
    return AlContentHeaderComponent;
}());
export { AlContentHeaderComponent };
/*@__PURE__*/ (function () { i0.ɵsetClassMetadata(AlContentHeaderComponent, [{
        type: Component,
        args: [{
                selector: 'al-content-header',
                templateUrl: './al-content-header.component.html',
                styleUrls: ['./al-content-header.component.scss'],
                encapsulation: ViewEncapsulation.None
            }]
    }], null, { icon: [{
            type: Input
        }], iconConfig: [{
            type: Input
        }], title: [{
            type: Input
        }], descriptionHeader: [{
            type: Input
        }], showAddButton: [{
            type: Input
        }], disableAddButton: [{
            type: Input
        }], addButtonTooltip: [{
            type: Input
        }], addMenuItems: [{
            type: Input
        }], defaultDate: [{
            type: Input
        }], showCalendar: [{
            type: Input
        }], showTime: [{
            type: Input
        }], dateTimePlaceholder: [{
            type: Input
        }], defaultFixedRanges: [{
            type: Input
        }], returnTimeFrame: [{
            type: Input
        }], showTimePicker: [{
            type: Input
        }], placeholder: [{
            type: Input
        }], selectorTitle: [{
            type: Input
        }], customRangeTitle: [{
            type: Input
        }], calendarMaxDaysHistory: [{
            type: Input
        }], calendarMaxDate: [{
            type: Input
        }], calendarMinDate: [{
            type: Input
        }], initialDateRangeSelection: [{
            type: Input
        }], onDateRangeSelectedFromAlDateRangeSelector: [{
            type: Output
        }], onClosedAlDateRangeSelector: [{
            type: Output
        }], onShowAlDateRangeSelector: [{
            type: Output
        }], onSelectFixedRangeAlDateRangeSelector: [{
            type: Output
        }], onDateRangeSelected: [{
            type: Output
        }], onButtonClicked: [{
            type: Output
        }], datePicker: [{
            type: ViewChild,
            args: ['datePicker']
        }], alDateSelector: [{
            type: ViewChild,
            args: ['alDateSelector']
        }] }); })();
//# sourceMappingURL=data:application/json;base64, 