import * as i0 from '@angular/core';
import { Injectable, Pipe, Inject, Component, NgModule } from '@angular/core';
import * as i1 from '@sellan/core';
import { Utility, CoreBaseDestroyComponent, CoreBaseModule, CoreMatModule, CoreControlModule, CoreDialogModule, CorePipeModule, CoreNotificationModule } from '@sellan/core';
import * as i1$1 from '@angular/material/dialog';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import * as i4 from '@angular/forms';
import * as i5 from 'ngx-scrollbar';
import * as i6 from '@angular/material/progress-bar';
import { of } from 'rxjs';

class GenerationService {
    constructor(_startUp, _ajaxM) {
        this._startUp = _startUp;
        this._ajaxM = _ajaxM;
    }
    generateBin(context) {
        const url = this._startUp.apiRoot('generate/binary', 'dgm');
        return this._ajaxM.post({ url: url, data: context });
    }
    generateLink(context) {
        const url = this._startUp.apiRoot('generate/link', 'dgm');
        return this._ajaxM.post({ url: url, data: context });
    }
    generateView(context) {
        const url = this._startUp.apiRoot('generate/view', 'dgm');
        return this._ajaxM.post({ url: url, data: context });
    }
    refreshView(context, result) {
        const url = this._startUp.apiRoot('generate/view/refresh', 'dgm');
        return this._ajaxM.post({ url: url, data: { context: context, parameters: result.parameters } });
    }
    saveView(context, result) {
        const url = this._startUp.apiRoot('generate/view/save', 'dgm');
        return this._ajaxM.post({ url: url, data: { context: context, parameters: result.parameters } });
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: GenerationService, deps: [{ token: i1.Startup }, { token: i1.AjaxService }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: GenerationService }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: GenerationService, decorators: [{
            type: Injectable
        }], ctorParameters: () => [{ type: i1.Startup }, { type: i1.AjaxService }] });

class ParameterFilterPipe {
    constructor() {
        this._filtered = false;
    }
    transform(items, filter) {
        if (Utility.isEmpty(filter) && this._filtered === true) {
            this._filtered = false;
            return [];
        }
        if (!items || !filter) {
            return items?.filter(item => item.value.viewerParameterType === 'TextBlock');
        }
        this._filtered = true;
        const f = filter.toLowerCase();
        return items.filter(item => item.value.viewerParameterType === 'TextBlock')
            .filter(item => item.name.toLowerCase().includes(f) === true || item.description.toLowerCase().includes(f) === true || item.key.toLowerCase().includes(f) === true);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: ParameterFilterPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
    static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.18", ngImport: i0, type: ParameterFilterPipe, isStandalone: false, name: "parameterFilter", pure: false }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: ParameterFilterPipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'parameterFilter',
                    pure: false,
                    standalone: false
                }]
        }] });

class DgmViewerDialogWindow extends CoreBaseDestroyComponent {
    get editableParams() {
        return this.result?.parameters?.filter(x => x.isEditable === true);
    }
    constructor(data, _dialogRef, _service, _popup, _ajaxM) {
        super();
        this._dialogRef = _dialogRef;
        this._service = _service;
        this._popup = _popup;
        this._ajaxM = _ajaxM;
        this.contentLoaded = false;
        this.context = data;
    }
    ngOnInit() {
        this._service
            .generateView(this.context)
            .pipe(this.takeUntilDestroyed())
            .subscribe((response) => this._popup.HandleIEntityResponse({
            response: response,
            successCallback: (entity) => {
                this.result = entity;
                this.fillURL(this.result.document.fileUrl);
            }
        }));
    }
    trackByIndex(index, obj) {
        return index;
    }
    trimPlaceholder(text) {
        return text.length > 20 ? text.substring(0, 20) + '...' : text;
    }
    getURL() {
        return this.url;
    }
    fillURL(fileUrl) {
        this._ajaxM
            .get({ url: fileUrl, httpOptions: { responseType: 'blob' } })
            .pipe(this.takeUntilDestroyed())
            .subscribe((response) => {
            const file = new Blob([response], { type: 'application/pdf' });
            this.url = URL.createObjectURL(file);
            this.contentLoaded = true;
        });
    }
    attach() {
        this._service
            .saveView(this.context, this.result)
            .pipe(this.takeUntilDestroyed())
            .subscribe((response) => this._popup.HandleIEntityResponse({
            response: response,
            successCallback: (entity) => {
                this._dialogRef.close(entity);
            }
        }));
    }
    refresh() {
        this._service
            .refreshView(this.context, this.result)
            .pipe(this.takeUntilDestroyed())
            .subscribe((response) => this._popup.HandleIEntityResponse({
            response: response,
            successCallback: (entity) => {
                this.result = entity;
                this.fillURL(this.result.document.fileUrl);
            }
        }));
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DgmViewerDialogWindow, deps: [{ token: MAT_DIALOG_DATA }, { token: i1$1.MatDialogRef }, { token: GenerationService }, { token: i1.PopupResults }, { token: i1.AjaxService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.18", type: DgmViewerDialogWindow, isStandalone: false, selector: "ng-component", usesInheritance: true, ngImport: i0, template: "<core-dialog dialogTitle=\"\u0424\u043E\u0440\u043C\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435 \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u0430\" fullScreen=\"true\" class=\"sln-dgm-viewer-modal\">\n  <div body>\n    <div class=\"row\">\n      @if (editableParams?.length > 0) {\n        <div class=\"col-md-3 sln-dgm-viewer-fields\">\n          <form #newForm=\"ngForm\" novalidate>\n            <div class=\"form-group\">\n              <core-field-string [(ngModel)]=\"searchKey\" name=\"searchKey\" fieldName=\"searchKey\" placeholder=\"\u041F\u043E\u0438\u0441\u043A \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u0430\"\n              class=\"sln-max-width\" [settings]=\"{ rightHintHide: true }\"></core-field-string>\n            </div>\n            <ng-scrollbar style=\"height:68vh;\">\n              @for (item of editableParams | parameterFilter: searchKey; track trackByIndex(i, item); let i = $index) {\n                <div class=\"form-group\">\n                  <div>\n                    @switch (item.value.viewerParameterType) {\n                      @case ('TextBlock') {\n                        <div style=\"display: flex;\">\n                          <core-field-string [(ngModel)]=\"item.value.text\" name=\"value_{{i}}_text\" fieldName=\"value_{{i}}_text\" [placeholder]=\"trimPlaceholder(item.name)\"\n                            class=\"sln-max-width\" [settings]=\"{ useInformer: item.name.length > 20, informerText: item.name, rightHintHide: true }\"\n                          labelClass=\"{{ item.isFail === true ? 'sln-dgm-viewer-label-error':'' }}\" cmpClass=\"{{ item.isFail === true ? 'sln-dgm-viewer-field-error':'' }}\"></core-field-string>\n                        </div>\n                      }\n                    }\n                  </div>\n                </div>\n              }\n            </ng-scrollbar>\n          </form>\n        </div>\n      }\n      <div class=\"col-md-{{ editableParams?.length > 0 ? '9' : '12' }} sln-dgm-viewer\">\n        @if (contentLoaded === false) {\n          <div class=\"sln-dgm-viwer-loading\">\n            <mat-progress-bar [hidden]=\"true\"  mode=\"indeterminate\"></mat-progress-bar>\n          </div>\n        }\n        @if (contentLoaded === true) {\n          <iframe [src]='getURL() | safe' type=\"application/pdf\" frameBorder=\"0\" scrolling=\"auto\"></iframe>\n        }\n      </div>\n    </div>\n  </div>\n  <div footer>\n    <button class=\"btn-primary\" (click)=\"attach()\">\u041F\u0440\u0438\u043A\u0440\u0435\u043F\u0438\u0442\u044C</button>\n    <button class=\"btn-default sln-dgm-viwer-button\" (click)=\"refresh()\">\u041F\u0435\u0440\u0435\u0444\u043E\u0440\u043C\u0438\u0440\u043E\u0432\u0430\u0442\u044C</button>\n  </div>\n</core-dialog>\n\n", styles: [".sln-field-filter-button{padding:0;min-width:0px;height:45px;width:20px;margin-top:5px;margin-left:3px}.form-group,.sln-field-layout{padding-right:10px}.sln-dgm-viwer-loading{margin-top:40vh}.sln-dgm-viwer-button{margin-left:5px}.sln-dgm-viewer-fields{padding:0}.sln-dgm-viewer-label-error{color:var(--DANGER)!important}.sln-dgm-viewer-field-error input{border-color:var(--DANGER)!important}.sln-dgm-viewer{padding-right:0}.sln-dgm-viewer iframe{width:100%;height:75vh;display:block}\n"], dependencies: [{ kind: "directive", type: i4.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i4.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i4.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i4.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "directive", type: i4.NgForm, selector: "form:not([ngNoForm]):not([formGroup]),ng-form,[ngForm]", inputs: ["ngFormOptions"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "component", type: i5.NgScrollbar, selector: "ng-scrollbar:not([externalViewport])", exportAs: ["ngScrollbar"] }, { kind: "component", type: i6.MatProgressBar, selector: "mat-progress-bar", inputs: ["color", "value", "bufferValue", "mode"], outputs: ["animationEnd"], exportAs: ["matProgressBar"] }, { kind: "component", type: i1.CoreFieldTypeStringComponent, selector: "core-field-string" }, { kind: "component", type: i1.CoreDialogWindow, selector: "core-dialog", inputs: ["dialogTitle", "hasCansel", "canselText", "hasFooter", "fullScreen", "width", "minWidth", "hasTitle", "leftMenu", "resizeble", "showTicketsVersions", "showCloseConfirmDialog", "beforeClosed", "cdkDragDisabled"] }, { kind: "pipe", type: i1.SafePipe, name: "safe" }, { kind: "pipe", type: ParameterFilterPipe, name: "parameterFilter" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DgmViewerDialogWindow, decorators: [{
            type: Component,
            args: [{ standalone: false, template: "<core-dialog dialogTitle=\"\u0424\u043E\u0440\u043C\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435 \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u0430\" fullScreen=\"true\" class=\"sln-dgm-viewer-modal\">\n  <div body>\n    <div class=\"row\">\n      @if (editableParams?.length > 0) {\n        <div class=\"col-md-3 sln-dgm-viewer-fields\">\n          <form #newForm=\"ngForm\" novalidate>\n            <div class=\"form-group\">\n              <core-field-string [(ngModel)]=\"searchKey\" name=\"searchKey\" fieldName=\"searchKey\" placeholder=\"\u041F\u043E\u0438\u0441\u043A \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u0430\"\n              class=\"sln-max-width\" [settings]=\"{ rightHintHide: true }\"></core-field-string>\n            </div>\n            <ng-scrollbar style=\"height:68vh;\">\n              @for (item of editableParams | parameterFilter: searchKey; track trackByIndex(i, item); let i = $index) {\n                <div class=\"form-group\">\n                  <div>\n                    @switch (item.value.viewerParameterType) {\n                      @case ('TextBlock') {\n                        <div style=\"display: flex;\">\n                          <core-field-string [(ngModel)]=\"item.value.text\" name=\"value_{{i}}_text\" fieldName=\"value_{{i}}_text\" [placeholder]=\"trimPlaceholder(item.name)\"\n                            class=\"sln-max-width\" [settings]=\"{ useInformer: item.name.length > 20, informerText: item.name, rightHintHide: true }\"\n                          labelClass=\"{{ item.isFail === true ? 'sln-dgm-viewer-label-error':'' }}\" cmpClass=\"{{ item.isFail === true ? 'sln-dgm-viewer-field-error':'' }}\"></core-field-string>\n                        </div>\n                      }\n                    }\n                  </div>\n                </div>\n              }\n            </ng-scrollbar>\n          </form>\n        </div>\n      }\n      <div class=\"col-md-{{ editableParams?.length > 0 ? '9' : '12' }} sln-dgm-viewer\">\n        @if (contentLoaded === false) {\n          <div class=\"sln-dgm-viwer-loading\">\n            <mat-progress-bar [hidden]=\"true\"  mode=\"indeterminate\"></mat-progress-bar>\n          </div>\n        }\n        @if (contentLoaded === true) {\n          <iframe [src]='getURL() | safe' type=\"application/pdf\" frameBorder=\"0\" scrolling=\"auto\"></iframe>\n        }\n      </div>\n    </div>\n  </div>\n  <div footer>\n    <button class=\"btn-primary\" (click)=\"attach()\">\u041F\u0440\u0438\u043A\u0440\u0435\u043F\u0438\u0442\u044C</button>\n    <button class=\"btn-default sln-dgm-viwer-button\" (click)=\"refresh()\">\u041F\u0435\u0440\u0435\u0444\u043E\u0440\u043C\u0438\u0440\u043E\u0432\u0430\u0442\u044C</button>\n  </div>\n</core-dialog>\n\n", styles: [".sln-field-filter-button{padding:0;min-width:0px;height:45px;width:20px;margin-top:5px;margin-left:3px}.form-group,.sln-field-layout{padding-right:10px}.sln-dgm-viwer-loading{margin-top:40vh}.sln-dgm-viwer-button{margin-left:5px}.sln-dgm-viewer-fields{padding:0}.sln-dgm-viewer-label-error{color:var(--DANGER)!important}.sln-dgm-viewer-field-error input{border-color:var(--DANGER)!important}.sln-dgm-viewer{padding-right:0}.sln-dgm-viewer iframe{width:100%;height:75vh;display:block}\n"] }]
        }], ctorParameters: () => [{ type: undefined, decorators: [{
                    type: Inject,
                    args: [MAT_DIALOG_DATA]
                }] }, { type: i1$1.MatDialogRef }, { type: GenerationService }, { type: i1.PopupResults }, { type: i1.AjaxService }] });

// тип источника данных
var EntityTypeEnum;
(function (EntityTypeEnum) {
    // Общий параметр, доступный для любого источника данных
    EntityTypeEnum[EntityTypeEnum["Common"] = 0] = "Common";
    // Заявка
    EntityTypeEnum[EntityTypeEnum["Request"] = 1] = "Request";
    // Распределение
    EntityTypeEnum[EntityTypeEnum["Distribution"] = 2] = "Distribution";
    // Организация
    EntityTypeEnum[EntityTypeEnum["Organization"] = 3] = "Organization";
    // Опросный лист клиента
    EntityTypeEnum[EntityTypeEnum["Profile"] = 4] = "Profile";
    // Финансовая отчетность
    EntityTypeEnum[EntityTypeEnum["Financial"] = 5] = "Financial";
    // Отчеты проверки документов
    EntityTypeEnum[EntityTypeEnum["Mra"] = 6] = "Mra";
    // Отчеты проверки документов
    EntityTypeEnum[EntityTypeEnum["RefreshRequest"] = 7] = "RefreshRequest";
    // МИДЛ: Карточка контракта
    EntityTypeEnum[EntityTypeEnum["MIDLContract"] = 100] = "MIDLContract";
    // МИДЛ: Карточка реестра
    EntityTypeEnum[EntityTypeEnum["MIDLRegistry"] = 101] = "MIDLRegistry";
})(EntityTypeEnum || (EntityTypeEnum = {}));
class IContextItem {
}

var ViewerParameterTypeEnum;
(function (ViewerParameterTypeEnum) {
    ViewerParameterTypeEnum["TextBlock"] = "TextBlock";
    ViewerParameterTypeEnum["CheckboxBlock"] = "CheckboxBlock";
    ViewerParameterTypeEnum["BoolBlock"] = "BoolBlock";
    ViewerParameterTypeEnum["Table"] = "Table";
    ViewerParameterTypeEnum["Link"] = "Link";
})(ViewerParameterTypeEnum || (ViewerParameterTypeEnum = {}));

class DgmComboboxUriDescriptionService {
    constructor(_startUp) {
        this._startUp = _startUp;
    }
    getUri(code) {
        const urls = [
            { code: 'DgmObjectTypes', url: () => this._startUp.apiRoot('generate/combobox/object-type', 'dgm') },
            { code: 'BpmFields', url: () => this._startUp.apiRoot('step-fields/combobox/process', 'bpm') }
        ];
        const url = urls.filter(x => x.code === code)[0]?.url();
        return url;
    }
    getLocalSourse(code, filters) {
        switch (code) {
            default: {
                return of({ isSuccess: true, message: '', entity: [] });
            }
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DgmComboboxUriDescriptionService, deps: [{ token: i1.Startup }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DgmComboboxUriDescriptionService }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DgmComboboxUriDescriptionService, decorators: [{
            type: Injectable
        }], ctorParameters: () => [{ type: i1.Startup }] });

class ParameterInfoService {
    constructor(_startUp, _ajaxM) {
        this._startUp = _startUp;
        this._ajaxM = _ajaxM;
    }
    getUsageInfo(key) {
        let url = this._startUp.apiRoot('parameters/usage/' + key, 'dgm');
        return this._ajaxM.get({ url: url });
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: ParameterInfoService, deps: [{ token: i1.Startup }, { token: i1.AjaxService }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: ParameterInfoService }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: ParameterInfoService, decorators: [{
            type: Injectable
        }], ctorParameters: () => [{ type: i1.Startup }, { type: i1.AjaxService }] });

class DgmModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DgmModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.18", ngImport: i0, type: DgmModule, declarations: [
            // directive
            // pages & components
            // dialogs
            DgmViewerDialogWindow,
            // pipes
            ParameterFilterPipe], imports: [CoreBaseModule,
            CoreMatModule,
            CoreControlModule,
            CoreDialogModule,
            CorePipeModule,
            CoreNotificationModule], exports: [
            // directive
            // pages & components
            // dialogs
            DgmViewerDialogWindow
            // pipes
        ] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DgmModule, providers: [
            // business services
            GenerationService,
            ParameterInfoService,
        ], imports: [CoreBaseModule,
            CoreMatModule,
            CoreControlModule,
            CoreDialogModule,
            CorePipeModule,
            CoreNotificationModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: DgmModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [
                        CoreBaseModule,
                        CoreMatModule,
                        CoreControlModule,
                        CoreDialogModule,
                        CorePipeModule,
                        CoreNotificationModule
                    ],
                    declarations: [
                        // directive
                        // pages & components
                        // dialogs
                        DgmViewerDialogWindow,
                        // pipes
                        ParameterFilterPipe
                    ],
                    providers: [
                        // business services
                        GenerationService,
                        ParameterInfoService,
                    ],
                    exports: [
                        // directive
                        // pages & components
                        // dialogs
                        DgmViewerDialogWindow
                        // pipes
                    ]
                }]
        }] });

/*
 * Public API Surface of sellan-dgm
 */
//components

/**
 * Generated bundle index. Do not edit.
 */

export { DgmComboboxUriDescriptionService, DgmModule, DgmViewerDialogWindow, EntityTypeEnum, GenerationService, IContextItem, ParameterInfoService, ViewerParameterTypeEnum };
//# sourceMappingURL=sellan-dgm.mjs.map
