import { Component, Inject } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { MatDialog, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { Subject } from 'rxjs';
import { DashboardListService } from '../dashboard-list.service';
import { SelectDashboardsDialogService } from './show-dashboards.service';
import { MatSnackBar } from '@angular/material/snack-bar';
import { DashboardDto } from '../../common-dto/dashboard-dto';
import { Router } from '@angular/router';
import { MAT_SELECT_CONFIG } from '@angular/material/select';
import { AxoSnackBarService, AxoSnackBarType } from '../../axo-snack-bar/axo-snack-bar.service';
import * as i0 from "@angular/core";
import * as i1 from "../dashboard-list.service";
import * as i2 from "./show-dashboards.service";
import * as i3 from "@angular/material/snack-bar";
import * as i4 from "../../axo-snack-bar/axo-snack-bar.service";
import * as i5 from "@angular/material/dialog";
import * as i6 from "@angular/router";
import * as i7 from "@angular/forms";
import * as i8 from "@angular/material/button";
import * as i9 from "@angular/common";
import * as i10 from "@angular/material/icon";
import * as i11 from "@angular/material/form-field";
import * as i12 from "@angular/material/select";
import * as i13 from "@angular/material/core";
import * as i14 from "@angular/material/input";
function SelectDashboardsDialogComponent_div_12_mat_option_6_Template(rf, ctx) { if (rf & 1) {
    const _r5 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "mat-option", 19);
    i0.ɵɵlistener("click", function SelectDashboardsDialogComponent_div_12_mat_option_6_Template_mat_option_click_0_listener() { const restoredCtx = i0.ɵɵrestoreView(_r5); const dashboard_r3 = restoredCtx.$implicit; const ctx_r4 = i0.ɵɵnextContext(2); return ctx_r4.onDashboardClick(dashboard_r3.id); });
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const dashboard_r3 = ctx.$implicit;
    i0.ɵɵproperty("value", dashboard_r3.id);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate1(" ", dashboard_r3.name, " ");
} }
function SelectDashboardsDialogComponent_div_12_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div");
    i0.ɵɵelementStart(1, "div", 15);
    i0.ɵɵelementStart(2, "mat-form-field", 16);
    i0.ɵɵelementStart(3, "mat-label");
    i0.ɵɵtext(4, "Select Existing Dashboard");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(5, "mat-select", 17);
    i0.ɵɵtemplate(6, SelectDashboardsDialogComponent_div_12_mat_option_6_Template, 2, 2, "mat-option", 18);
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance(5);
    i0.ɵɵproperty("disableOptionCentering", true);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngForOf", ctx_r0.dashboards);
} }
function SelectDashboardsDialogComponent_div_13_mat_error_6_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "mat-error");
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r6 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate(ctx_r6.getErrorMessage());
} }
function SelectDashboardsDialogComponent_div_13_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div");
    i0.ɵɵelementStart(1, "div", 15);
    i0.ɵɵelementStart(2, "mat-form-field", 16);
    i0.ɵɵelementStart(3, "mat-label");
    i0.ɵɵtext(4, "Create New Dashboard");
    i0.ɵɵelementEnd();
    i0.ɵɵelement(5, "input", 20);
    i0.ɵɵtemplate(6, SelectDashboardsDialogComponent_div_13_mat_error_6_Template, 2, 1, "mat-error", 7);
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance(5);
    i0.ɵɵproperty("formControl", ctx_r1.dashboardName);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r1.dashboardName.invalid && ctx_r1.dashboardName.touched);
} }
const _c0 = function (a0) { return { "active-selected": a0 }; };
export class SelectDashboardsDialogComponent {
    constructor(_dashboardListService, _showDashboardComponentService, _snackBar, _axoSnackBar, dialog, data, router) {
        this._dashboardListService = _dashboardListService;
        this._showDashboardComponentService = _showDashboardComponentService;
        this._snackBar = _snackBar;
        this._axoSnackBar = _axoSnackBar;
        this.dialog = dialog;
        this.data = data;
        this.router = router;
        this.dashboards = [];
        this.showDashboard = true;
        this.createDashboard = false;
        this.elements = [];
        this.dashboardName = new FormControl('', Validators.required);
        this.isDashboardNameEmpty = true;
        this._unsubscribeAll = new Subject();
    }
    ngOnInit() {
        // to get existing dashboard list
        this._dashboardListService.getDashboardList(this.data.appVersionId).subscribe((dashboard) => {
            this.dashboards = dashboard;
        });
    }
    showDashboardList() {
        this.showDashboard = true;
        this.createDashboard = false;
    }
    createDashboardList() {
        this.showDashboard = false;
        this.createDashboard = true;
    }
    onNoClick() {
        const dialogRef = this.dialog.closeAll();
    }
    onDashboardClick(dashboardId) {
        this.dashboardId = dashboardId;
    }
    async pinToDashboard() {
        this.dashboardName.markAsTouched();
        if (this.showDashboard) {
            const dashboardData = new DashboardDto(this.data);
            dashboardData.dashboardId = this.dashboardId;
            this._axoSnackBar.openSnackBar('Pinning to dashboard...', AxoSnackBarType.info);
            await this._showDashboardComponentService.sendToDashboard(dashboardData);
            const snackBarRef = this._snackBar.open('Report pinned to dashboard.', 'View Dashboard', { duration: 5000, panelClass: 'pinned-dashboard' });
            snackBarRef.onAction().subscribe(() => {
                const url = this.router.createUrlTree(['apps/' + this.data.appVersionId + '/dashboards/' + this.dashboardId]);
                window.open(url.toString(), '_blank');
            });
        }
        else {
            const dashboardData = new DashboardDto(this.data);
            dashboardData.name = this.dashboardName.value;
            this._axoSnackBar.openSnackBar('Pinning to dashboard...', AxoSnackBarType.info);
            const dashboardId = await this._showDashboardComponentService.createSendToDashboard(dashboardData);
            const snackBarRef = this._snackBar.open('Report pinned to dashboard.', 'View Dashboard', { duration: 5000, panelClass: 'pinned-dashboard' });
            snackBarRef.onAction().subscribe(() => {
                const url = this.router.createUrlTree(['apps/' + this.data.appVersionId + '/dashboards/' + dashboardId]);
                window.open(url.toString(), '_blank');
            });
        }
        const dialogRef = this.dialog.closeAll();
    }
    getErrorMessage() {
        if (this.dashboardName.hasError('required')) {
            this.isDashboardNameEmpty = false;
            return 'Please enter dashboard name';
        }
    }
    /**
     *
     * @param message
     */
    openSnackBar(message) {
        this._snackBar.open(message);
    }
}
SelectDashboardsDialogComponent.ɵfac = function SelectDashboardsDialogComponent_Factory(t) { return new (t || SelectDashboardsDialogComponent)(i0.ɵɵdirectiveInject(i1.DashboardListService), i0.ɵɵdirectiveInject(i2.SelectDashboardsDialogService), i0.ɵɵdirectiveInject(i3.MatSnackBar), i0.ɵɵdirectiveInject(i4.AxoSnackBarService), i0.ɵɵdirectiveInject(i5.MatDialog), i0.ɵɵdirectiveInject(MAT_DIALOG_DATA), i0.ɵɵdirectiveInject(i6.Router)); };
SelectDashboardsDialogComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: SelectDashboardsDialogComponent, selectors: [["lib-show-dashboards"]], features: [i0.ɵɵProvidersFeature([
            {
                provide: MAT_SELECT_CONFIG,
                useValue: { overlayPanelClass: 'send-dashboard-custom-overlay-panel' },
            },
        ])], decls: 25, vars: 12, consts: [[1, "flex", "flex-col"], [1, "mb-4", "pin-to-dashboard"], [1, "flex", "items-center", "mt-6", "mb-4", "sm:mt-0", "dash-btns", "space-x-3"], ["mat-flat-button", "", 1, "btn-1", 3, "disableRipple", "ngClass", "click"], [1, ""], ["type", "button", "mat-flat-button", "", 1, "btn-2", 3, "disableRipple", "ngClass", "click"], [1, "border", "h-28", "p-3"], [4, "ngIf"], [1, "mt-5"], [1, "flex", "items-end", "btns", "sm:mt-0", "sm:ml-5", "space-x-3"], [1, "cancel-btn"], ["mat-flat-button", "", 3, "autofocus", "click"], [1, "pin-btn"], ["mat-flat-button", "", "type", "submit", 1, "flex", "items-start", 3, "click"], [3, "svgIcon"], [1, "flex", "flex-col", "gt-xs:flex-row"], [1, "flex-auto", "gt-xs:pr-3"], ["panelClass", "show-dash", "required", "", 3, "disableOptionCentering"], ["required", "", "class", "sss", 3, "value", "click", 4, "ngFor", "ngForOf"], ["required", "", 1, "sss", 3, "value", "click"], ["matInput", "", "id", "createnewdashboard", "name", "createnewdashbaord", 3, "formControl"]], template: function SelectDashboardsDialogComponent_Template(rf, ctx) { if (rf & 1) {
        i0.ɵɵelementStart(0, "form", 0);
        i0.ɵɵelementStart(1, "div");
        i0.ɵɵelementStart(2, "div", 1);
        i0.ɵɵtext(3, "Pin to Dashboard");
        i0.ɵɵelementEnd();
        i0.ɵɵelementStart(4, "div", 2);
        i0.ɵɵelementStart(5, "button", 3);
        i0.ɵɵlistener("click", function SelectDashboardsDialogComponent_Template_button_click_5_listener() { return ctx.showDashboardList(); });
        i0.ɵɵelementStart(6, "span", 4);
        i0.ɵɵtext(7, "Existing Dashboard");
        i0.ɵɵelementEnd();
        i0.ɵɵelementEnd();
        i0.ɵɵelementStart(8, "button", 5);
        i0.ɵɵlistener("click", function SelectDashboardsDialogComponent_Template_button_click_8_listener() { return ctx.createDashboardList(); });
        i0.ɵɵelementStart(9, "span", 4);
        i0.ɵɵtext(10, "Create New Dashboard");
        i0.ɵɵelementEnd();
        i0.ɵɵelementEnd();
        i0.ɵɵelementEnd();
        i0.ɵɵelementStart(11, "div", 6);
        i0.ɵɵtemplate(12, SelectDashboardsDialogComponent_div_12_Template, 7, 2, "div", 7);
        i0.ɵɵtemplate(13, SelectDashboardsDialogComponent_div_13_Template, 7, 2, "div", 7);
        i0.ɵɵelementEnd();
        i0.ɵɵelementEnd();
        i0.ɵɵelementStart(14, "div", 8);
        i0.ɵɵelementStart(15, "div", 9);
        i0.ɵɵelementStart(16, "div", 10);
        i0.ɵɵelementStart(17, "button", 11);
        i0.ɵɵlistener("click", function SelectDashboardsDialogComponent_Template_button_click_17_listener() { return ctx.onNoClick(); });
        i0.ɵɵelementStart(18, "span");
        i0.ɵɵtext(19, "Cancel");
        i0.ɵɵelementEnd();
        i0.ɵɵelementEnd();
        i0.ɵɵelementEnd();
        i0.ɵɵelementStart(20, "div", 12);
        i0.ɵɵelementStart(21, "button", 13);
        i0.ɵɵlistener("click", function SelectDashboardsDialogComponent_Template_button_click_21_listener() { return ctx.pinToDashboard(); });
        i0.ɵɵelement(22, "mat-icon", 14);
        i0.ɵɵelementStart(23, "span");
        i0.ɵɵtext(24, " Pin");
        i0.ɵɵelementEnd();
        i0.ɵɵelementEnd();
        i0.ɵɵelementEnd();
        i0.ɵɵelementEnd();
        i0.ɵɵelementEnd();
        i0.ɵɵelementEnd();
    } if (rf & 2) {
        i0.ɵɵadvance(5);
        i0.ɵɵproperty("disableRipple", true)("ngClass", i0.ɵɵpureFunction1(8, _c0, ctx.showDashboard));
        i0.ɵɵadvance(3);
        i0.ɵɵproperty("disableRipple", true)("ngClass", i0.ɵɵpureFunction1(10, _c0, !ctx.showDashboard));
        i0.ɵɵadvance(4);
        i0.ɵɵproperty("ngIf", ctx.showDashboard);
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngIf", ctx.createDashboard);
        i0.ɵɵadvance(4);
        i0.ɵɵproperty("autofocus", false);
        i0.ɵɵadvance(5);
        i0.ɵɵproperty("svgIcon", "axo_pin");
    } }, directives: [i7.ɵNgNoValidate, i7.NgControlStatusGroup, i7.NgForm, i8.MatButton, i9.NgClass, i9.NgIf, i10.MatIcon, i11.MatFormField, i11.MatLabel, i12.MatSelect, i9.NgForOf, i13.MatOption, i14.MatInput, i7.DefaultValueAccessor, i7.NgControlStatus, i7.FormControlDirective, i11.MatError], styles: [".pin-to-dashboard[_ngcontent-%COMP%]{font-size:20px;font-weight:500}.dash-btns[_ngcontent-%COMP%]   .mat-flat-button[_ngcontent-%COMP%]{border-radius:5px!important;max-height:39px;min-height:12px;border:.1px dashed #ED955A}.dash-btns[_ngcontent-%COMP%]   .active-selected[_ngcontent-%COMP%]{background:#ED955A 0% 0% no-repeat padding-box;border-radius:4px;color:#fff;opacity:1}.btns[_ngcontent-%COMP%]{margin-left:5.5rem;float:right}.btns[_ngcontent-%COMP%]   .mat-flat-button[_ngcontent-%COMP%]{border:.1px dashed #6454c0}.cancel-btn[_ngcontent-%COMP%]   .mat-flat-button[_ngcontent-%COMP%]{border-radius:5px!important;max-height:39px!important;min-height:12px;border:.1px dashed #ED955A}.cancel-btn[_ngcontent-%COMP%]   .mat-flat-button[_ngcontent-%COMP%]:hover{background:#FFF!important;border-radius:4px!important;color:#000;opacity:1}.dash-btns[_ngcontent-%COMP%]   .mat-flat-button[_ngcontent-%COMP%]:hover{background:#ED955A;border-radius:4px!important;color:#fff;opacity:1}.pin-btn[_ngcontent-%COMP%]   .mat-flat-button[_ngcontent-%COMP%]{background-color:#6454c0!important;color:#fff;border-radius:5px!important;max-height:39px!important;min-height:12px;width:100px}.pin-btn[_ngcontent-%COMP%]   mat-icon[_ngcontent-%COMP%]{min-width:16px;max-height:16px;width:16px;height:16px;left:-14px;position:relative}  .mat-button-focus-overlay{display:none}  .pinned-dashboard{background-color:#ddd!important;color:#000!important}  .pinned-dashboard .mat-simple-snackbar-action{color:#0645ad!important;text-decoration:underline}  .mat-form-field-required-marker{color:#f00b0b!important}  .send-dashboard-custom-overlay-panel{margin-top:2.3rem}"] });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(SelectDashboardsDialogComponent, [{
        type: Component,
        args: [{ selector: 'lib-show-dashboards', providers: [
                    {
                        provide: MAT_SELECT_CONFIG,
                        useValue: { overlayPanelClass: 'send-dashboard-custom-overlay-panel' },
                    },
                ], template: "<form class=\"flex flex-col\">\n      <div>\n        <div class=\"mb-4 pin-to-dashboard\">Pin to Dashboard</div>\n        <div class=\"flex items-center  mt-6 mb-4 sm:mt-0 dash-btns space-x-3\">\n            <button [disableRipple]=\"true\" [ngClass]=\"{'active-selected':showDashboard }\" (click)=\"showDashboardList()\" class=\"btn-1\" mat-flat-button>\n            <span class=\"\">Existing Dashboard</span>\n          </button>\n          <button [disableRipple]=\"true\" [ngClass]=\"{'active-selected':!showDashboard }\" type=\"button\" (click)=\"createDashboardList()\" class=\"btn-2\" mat-flat-button>\n            <span class=\"\">Create New Dashboard</span>\n          </button>   \n        </div>\n    \n        <div class=\"border h-28 p-3\">\n          <div *ngIf=\"showDashboard\">\n            <div class=\"flex flex-col gt-xs:flex-row\">\n              <mat-form-field class=\"flex-auto gt-xs:pr-3\">\n                <mat-label>Select Existing Dashboard</mat-label>\n                <mat-select  panelClass=\"show-dash\" [disableOptionCentering]=\"true\" required>\n                  <mat-option *ngFor=\"let dashboard of dashboards\" [value]=\"dashboard.id\" (click)=\"onDashboardClick(dashboard.id)\" required class=\"sss\">\n                    {{dashboard.name}}\n                  </mat-option>\n                </mat-select>\n              </mat-form-field>\n            </div>\n          </div>\n\n          <div *ngIf=\"createDashboard\">\n            <div class=\"flex flex-col gt-xs:flex-row\">\n              <mat-form-field class=\"flex-auto gt-xs:pr-3\">\n                <mat-label>Create New Dashboard</mat-label>\n                <input matInput [formControl]=\"dashboardName\" id=\"createnewdashboard\" name=\"createnewdashbaord\">\n                <mat-error *ngIf=\"dashboardName.invalid && dashboardName.touched\">{{getErrorMessage()}}</mat-error>\n\n              </mat-form-field>\n            </div>\n\n          </div>\n        </div>\n      </div>\n\n    <div class=\"mt-5\">\n    \n      <div class=\"flex items-end  btns sm:mt-0 sm:ml-5 space-x-3\">\n        <div class=\"cancel-btn\">\n        <button (click)=\"onNoClick()\"[autofocus]=\"false\" mat-flat-button>\n          <span>Cancel</span>\n        </button>\n      </div>\n        <div class=\"pin-btn\">\n          <button class=\"flex items-start\" mat-flat-button type=\"submit\" (click)=\"pinToDashboard()\" >\n            <mat-icon [svgIcon]=\"'axo_pin'\" ></mat-icon>\n            <span> Pin</span>\n          </button>\n        </div>\n      </div>\n    </div>\n  </form>", styles: [".pin-to-dashboard{font-size:20px;font-weight:500}.dash-btns .mat-flat-button{border-radius:5px!important;max-height:39px;min-height:12px;border:.1px dashed #ED955A}.dash-btns .active-selected{background:#ED955A 0% 0% no-repeat padding-box;border-radius:4px;color:#fff;opacity:1}.btns{margin-left:5.5rem;float:right}.btns .mat-flat-button{border:.1px dashed #6454c0}.cancel-btn .mat-flat-button{border-radius:5px!important;max-height:39px!important;min-height:12px;border:.1px dashed #ED955A}.cancel-btn .mat-flat-button:hover{background:#FFF!important;border-radius:4px!important;color:#000;opacity:1}.dash-btns .mat-flat-button:hover{background:#ED955A;border-radius:4px!important;color:#fff;opacity:1}.pin-btn .mat-flat-button{background-color:#6454c0!important;color:#fff;border-radius:5px!important;max-height:39px!important;min-height:12px;width:100px}.pin-btn mat-icon{min-width:16px;max-height:16px;width:16px;height:16px;left:-14px;position:relative}::ng-deep .mat-button-focus-overlay{display:none}::ng-deep .pinned-dashboard{background-color:#ddd!important;color:#000!important}::ng-deep .pinned-dashboard .mat-simple-snackbar-action{color:#0645ad!important;text-decoration:underline}::ng-deep .mat-form-field-required-marker{color:#f00b0b!important}::ng-deep .send-dashboard-custom-overlay-panel{margin-top:2.3rem}\n"] }]
    }], function () { return [{ type: i1.DashboardListService }, { type: i2.SelectDashboardsDialogService }, { type: i3.MatSnackBar }, { type: i4.AxoSnackBarService }, { type: i5.MatDialog }, { type: undefined, decorators: [{
                type: Inject,
                args: [MAT_DIALOG_DATA]
            }] }, { type: i6.Router }]; }, null); })();
//# sourceMappingURL=data:application/json;base64, 