/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
 */
import { Component } from '@angular/core';
import { DisplayStateService } from '../../../../../services/DisplayStateService';
import { WebPlatformApiService } from '../../../../../services/WebPlatformApiService';
export class LandingEditorModalComponent {
    /**
     * @param {?} displayStateService
     * @param {?} webPlatformApiService
     */
    constructor(displayStateService, webPlatformApiService) {
        this.displayStateService = displayStateService;
        this.webPlatformApiService = webPlatformApiService;
        this.viewsJSONcls = '';
        this.linksJSONcls = '';
    }
    /**
     * @return {?}
     */
    ngOnInit() {
        setTimeout(() => {
            // slight delay to allow the landingConfig to be set by the parent component
            this.landingConfig = JSON.parse(JSON.stringify(this.widgetConfig.config));
            this.grabJSON();
        }, 100);
    }
    /**
     * @return {?}
     */
    grabJSON() {
        this.viewsJSON = JSON.stringify(this.landingConfig.Views, null, 2);
        this.linksJSON = JSON.stringify(this.landingConfig.ExternalLinks, null, 2);
        this.viewsJSONcls = '';
        this.linksJSONcls = '';
    }
    /**
     * @return {?}
     */
    checkJSON() {
        /** @type {?} */
        let newViews;
        /** @type {?} */
        let newExtLinks;
        try {
            newViews = JSON.parse(this.viewsJSON);
            newExtLinks = JSON.parse(this.linksJSON);
            this.landingConfig.Views = newViews;
            this.landingConfig.ExternalLinks = newExtLinks;
            this.grabJSON();
        }
        catch (e) {
            alert('Error Parsing:' + JSON.stringify(e));
        }
    }
    /**
     * @return {?}
     */
    addExtWidgetConfig() {
        this.landingConfig.ExternalWidgetsConfigUrls.push({ instanceName: null, url: null });
    }
    /**
     * @param {?} ix
     * @return {?}
     */
    deleteExtWidgetConfigByIndex(ix) {
        this.landingConfig.ExternalWidgetsConfigUrls.splice(ix, 1);
    }
    /**
     * @return {?}
     */
    saveDb() {
        this.widgetConfig.config = this.landingConfig;
        this.webPlatformApiService.SaveSingleConfiguration('WidgetConfigurationList', this.widgetConfig, this.widgetConfig.name)
            .subscribe(x => {
            if (x.status === 'conflict') {
                this.displayStateService.RaiseErrorToast(`Conflicts detected, changes not saved.`);
            }
            else {
                this.displayStateService.RaiseSuccessToast(`${this.widgetConfig.name} Saved to Data base.`);
                this.modalRef.hide();
            }
        }, error => this.displayStateService.RaiseErrorToast(error));
    }
    /**
     * @return {?}
     */
    cancelEdit() {
        this.viewsJSON = '';
        this.linksJSON = '';
        this.viewsJSONcls = '';
        this.linksJSONcls = '';
        this.modalRef.hide();
    }
}
LandingEditorModalComponent.decorators = [
    { type: Component, args: [{
                selector: 'landing-editor-modal',
                template: "<ng-container *ngIf=\"landingConfig != null\">\r\n  <div class=\"modal-header\">\r\n    <h4 class=\"modal-title\">Customize Landing Page</h4>\r\n    <button type=\"button\" class=\"close pull-right\" aria-label=\"Close\" (click)=\"modalRef.hide()\">\r\n      <span aria-hidden=\"true\">&times;</span>\r\n    </button>\r\n  </div>\r\n  <div class=\"modal-body mx-3\">\r\n    <div class=\"form-check mx-3\">\r\n      <input type=\"checkbox\" class=\"form-check-input\" id=\"sfbtDrop\" [(ngModel)]=\"landingConfig.ShowFilterByTags\">\r\n      <label class=\"form-check-label\" for=\"hfbtDrop\">Show Filter By Group Dropdown</label>\r\n    </div>\r\n    <div class=\"form-check mx-3\">\r\n      <input type=\"checkbox\" class=\"form-check-input\" id=\"sqSearch\" [(ngModel)]=\"landingConfig.ShowQuickSearch\">\r\n      <label class=\"form-check-label\" for=\"sqSearch\">Show Quick Search</label>\r\n    </div>\r\n    <div class=\"form-check mx-3\">\r\n      <input type=\"checkbox\" class=\"form-check-input\" id=\"svSelect\" [(ngModel)]=\"landingConfig.ShowViewsSelector\">\r\n      <label class=\"form-check-label\" for=\"svSelect\">Show Views Selector</label>\r\n    </div>\r\n    <div class=\"form-group my-2\">\r\n      <button type=\"button\" class=\"btn btn-outline-info btn-sm\" (click)=\"addExtWidgetConfig()\">\r\n          Add External Widgets Config API Url\r\n      </button>\r\n      <div class=\"form-group my-2 row no-gutters\" *ngFor=\"let nv of landingConfig.ExternalWidgetsConfigUrls; let idx = index\">\r\n        <input type=\"text\" class=\"mx-1 col-sm-4 form-control\" [(ngModel)]=\"nv.instanceName\" placeholder=\"name the external instance\">\r\n        <input type=\"text\" class=\"mx-1 col-sm-6 form-control\" [(ngModel)]=\"nv.url\" placeholder=\"URL of an external Omelek instance ex: http://bowauxweb01.micron.com/XWebPlatform/\">\r\n        <div class=\"col-sm-1 text-center\">\r\n          <button type=\"button\" class=\"btn btn-danger btn-sm\" (click)=\"deleteExtWidgetConfigByIndex(idx)\">\r\n            <i _ngcontent-c24=\"\" class=\"fa fa-times\"></i>\r\n          </button>\r\n        </div>\r\n      </div>\r\n    </div>\r\n    <label for=\"LandingViewsConfig\">Configure Landing Page Views</label>\r\n    <button type=\"button\" class=\"btn btn-outline-info btn-sm\" [ngClass]=\"viewsJSONcls\" (click)=\"checkJSON()\">\r\n        Validate Views Config\r\n    </button>\r\n    <textarea style=\"width: 100%; height: 400px; font-family: monospace\" \r\n      [ngClass]=\"viewsJSONcls\" [(ngModel)]=\"viewsJSON\" (ngModelChange)=\"viewsJSONcls = 'alert-danger'\"\r\n      id=\"LandingViewsConfig\" name=\"LandingViewsConfig\"></textarea>\r\n    <label for=\"LandingExternalLinks\">Configure External Links</label>\r\n    <button type=\"button\" class=\"btn btn-outline-info btn-sm\" [ngClass]=\"linksJSONcls\" (click)=\"checkJSON()\">\r\n        Validate External Links Config\r\n    </button>\r\n    <textarea style=\"width: 100%; height: 400px; font-family: monospace;\" \r\n      [ngClass]=\"linksJSONcls\" [(ngModel)]=\"linksJSON\" (ngModelChange)=\"linksJSONcls = 'alert-danger'\"\r\n      id=\"LandingExternalLinks\" name=\"LandingExternalLinks\"></textarea>\r\n    <!-- <div class=\"card p-2 mb-2\">\r\n      {{ landingConfig | json }}\r\n    </div> -->\r\n  </div>\r\n  <div class=\"modal-footer\">\r\n    <button type=\"button\" class=\"btn btn-outline-success\" (click)=\"saveDb()\">Save</button>\r\n    <button type=\"button\" class=\"btn btn-outline-danger\" (click)=\"cancelEdit()\">Cancel</button>\r\n  </div>\r\n</ng-container>",
                styles: [""]
            }] }
];
/** @nocollapse */
LandingEditorModalComponent.ctorParameters = () => [
    { type: DisplayStateService },
    { type: WebPlatformApiService }
];
if (false) {
    /** @type {?} */
    LandingEditorModalComponent.prototype.modalRef;
    /** @type {?} */
    LandingEditorModalComponent.prototype.widgetConfig;
    /** @type {?} */
    LandingEditorModalComponent.prototype.landingConfig;
    /** @type {?} */
    LandingEditorModalComponent.prototype.viewsJSON;
    /** @type {?} */
    LandingEditorModalComponent.prototype.viewsJSONcls;
    /** @type {?} */
    LandingEditorModalComponent.prototype.linksJSON;
    /** @type {?} */
    LandingEditorModalComponent.prototype.linksJSONcls;
    /** @type {?} */
    LandingEditorModalComponent.prototype.displayStateService;
    /** @type {?} */
    LandingEditorModalComponent.prototype.webPlatformApiService;
}

//# sourceMappingURL=data:application/json;base64, 