import { __awaiter } from "tslib";
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input } from '@angular/core';
import { FormControl } from '@angular/forms';
import { FirstUppercaseLocalizeSAPipe } from '@anglr/common';
import { TitledDialogService } from '@anglr/common/material';
import { CodeEditorDialogComponent } from '@anglr/dynamic';
import { isBlank, isPresent } from '@jscrpt/common';
import { lastValueFrom } from '@jscrpt/common/rxjs';
import { PropertiesControlBase } from '../../modules';
import { LayoutEditorMetadataExtractor } from '../../services';
import * as i0 from "@angular/core";
import * as i1 from "../../services";
import * as i2 from "@anglr/common/material";
/**
 * Base component used for displaying code properties control
 */
export class BaseCodePropertiesControlSAComponent extends PropertiesControlBase {
    //######################### constructor #########################
    constructor(changeDetector, metadataExtractor, dialog) {
        super(changeDetector, metadataExtractor);
        this.dialog = dialog;
    }
    //######################### protected methods - template bindings #########################
    /**
     * Shows code editor
     */
    showCodeEditor() {
        var _a, _b, _c, _d;
        return __awaiter(this, void 0, void 0, function* () {
            if (isBlank(this.property) || !this.languageModel) {
                return;
            }
            const result = yield lastValueFrom(this.dialog.open(CodeEditorDialogComponent, {
                title: 'Code editor',
                width: '75vw',
                height: '75vh',
                data: {
                    content: (_c = (_b = (_a = this.form) === null || _a === void 0 ? void 0 : _a.get(this.property)) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : '',
                    languageModel: this.languageModel
                }
            }).afterClosed());
            if (isPresent(result)) {
                const control = (_d = this.form) === null || _d === void 0 ? void 0 : _d.get(this.property);
                if (control instanceof FormControl) {
                    control.setValue(result.content);
                }
            }
        });
    }
}
BaseCodePropertiesControlSAComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: BaseCodePropertiesControlSAComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i1.LayoutEditorMetadataExtractor }, { token: i2.TitledDialogService }], target: i0.ɵɵFactoryTarget.Component });
BaseCodePropertiesControlSAComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.4", type: BaseCodePropertiesControlSAComponent, isStandalone: true, selector: "base-code-properties-control", inputs: { property: "property", languageModel: "languageModel" }, usesInheritance: true, ngImport: i0, template: "<div class=\"properties-form-group ng-star-inserted\">\n    <label class=\"properties-control-label\">&nbsp;</label>\n    <div class=\"properties-form-actions\">\n        <button type=\"button\" type=\"button\" class=\"dynamic-btn dynamic-btn-primary dynamic-margin-vertical-small\" (click)=\"showCodeEditor()\">\n            <span>{{'edit'|firstUppercaseLocalize}} {{property}}</span>\n        </button>\n    </div>\n</div>", dependencies: [{ kind: "pipe", type: FirstUppercaseLocalizeSAPipe, name: "firstUppercaseLocalize" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: BaseCodePropertiesControlSAComponent, decorators: [{
            type: Component,
            args: [{ selector: 'base-code-properties-control', standalone: true, imports: [
                        FirstUppercaseLocalizeSAPipe,
                    ], changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"properties-form-group ng-star-inserted\">\n    <label class=\"properties-control-label\">&nbsp;</label>\n    <div class=\"properties-form-actions\">\n        <button type=\"button\" type=\"button\" class=\"dynamic-btn dynamic-btn-primary dynamic-margin-vertical-small\" (click)=\"showCodeEditor()\">\n            <span>{{'edit'|firstUppercaseLocalize}} {{property}}</span>\n        </button>\n    </div>\n</div>" }]
        }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }, { type: i1.LayoutEditorMetadataExtractor }, { type: i2.TitledDialogService }], propDecorators: { property: [{
                type: Input
            }], languageModel: [{
                type: Input
            }] } });
/**
 * Gets code properties control component for specific property
 * @param property - Name of property that will be set by this component
 * @param languageModel - Language model to be used in code editor
 */
export function codePropertiesControlFor(property, languageModel) {
    class CodePropertiesControl extends BaseCodePropertiesControlSAComponent {
        constructor() {
            super(...arguments);
            /**
             * @inheritdoc
             */
            this.property = property;
            /**
             * @inheritdoc
             */
            this.languageModel = languageModel;
        }
    }
    CodePropertiesControl.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: CodePropertiesControl, deps: null, target: i0.ɵɵFactoryTarget.Component });
    CodePropertiesControl.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.4", type: CodePropertiesControl, isStandalone: true, selector: "code-properties-control", inputs: { property: "property", languageModel: "languageModel" }, usesInheritance: true, ngImport: i0, template: "<div class=\"properties-form-group ng-star-inserted\">\n    <label class=\"properties-control-label\">&nbsp;</label>\n    <div class=\"properties-form-actions\">\n        <button type=\"button\" type=\"button\" class=\"dynamic-btn dynamic-btn-primary dynamic-margin-vertical-small\" (click)=\"showCodeEditor()\">\n            <span>{{'edit'|firstUppercaseLocalize}} {{property}}</span>\n        </button>\n    </div>\n</div>", dependencies: [{ kind: "pipe", type: FirstUppercaseLocalizeSAPipe, name: "firstUppercaseLocalize" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
    i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: CodePropertiesControl, decorators: [{
                type: Component,
                args: [{ selector: 'code-properties-control', standalone: true, imports: [
                            FirstUppercaseLocalizeSAPipe,
                        ], changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"properties-form-group ng-star-inserted\">\n    <label class=\"properties-control-label\">&nbsp;</label>\n    <div class=\"properties-form-actions\">\n        <button type=\"button\" type=\"button\" class=\"dynamic-btn dynamic-btn-primary dynamic-margin-vertical-small\" (click)=\"showCodeEditor()\">\n            <span>{{'edit'|firstUppercaseLocalize}} {{property}}</span>\n        </button>\n    </div>\n</div>" }]
            }], propDecorators: { property: [{
                    type: Input
                }], languageModel: [{
                    type: Input
                }] } });
    return CodePropertiesControl;
}
//# sourceMappingURL=codePropertiesControl.component.js.map