import { __awaiter } from "tslib";
import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core';
import { FormControl } from '@angular/forms';
import { TitledDialogService } from '@anglr/common/material';
import { LayoutEditorMetadataExtractor, PropertiesControlBase } from '@anglr/dynamic/layout-editor';
import { isPresent } from '@jscrpt/common';
import { lastValueFrom } from '@jscrpt/common/rxjs';
import { RichTextBlockEditorDialogSAComponent } from '../richTextBlockEditorDialog/richTextBlockEditorDialog.component';
import * as i0 from "@angular/core";
import * as i1 from "@anglr/dynamic/layout-editor";
import * as i2 from "@anglr/common/material";
/**
 * Component used for displaying rich text block properties control
 */
export class RichTextBlockPropertiesControlSAComponent extends PropertiesControlBase {
    //######################### constructor #########################
    constructor(changeDetector, metadataExtractor, dialog) {
        super(changeDetector, metadataExtractor);
        this.dialog = dialog;
    }
    //######################### protected methods - template bindings #########################
    /**
     * Shows code editor
     */
    showCodeEditor() {
        var _a, _b;
        return __awaiter(this, void 0, void 0, function* () {
            const result = yield lastValueFrom(this.dialog.open(RichTextBlockEditorDialogSAComponent, {
                title: 'Rich text block editor',
                width: '75vw',
                height: '75vh',
                data: (_a = this.form) === null || _a === void 0 ? void 0 : _a.controls.content.value
            }).afterClosed());
            if (isPresent(result)) {
                const control = (_b = this.form) === null || _b === void 0 ? void 0 : _b.controls.content;
                if (control instanceof FormControl) {
                    control.setValue(result);
                }
            }
        });
    }
}
RichTextBlockPropertiesControlSAComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: RichTextBlockPropertiesControlSAComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i1.LayoutEditorMetadataExtractor }, { token: i2.TitledDialogService }], target: i0.ɵɵFactoryTarget.Component });
RichTextBlockPropertiesControlSAComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.4", type: RichTextBlockPropertiesControlSAComponent, isStandalone: true, selector: "rich-text-block-properties-control", usesInheritance: true, ngImport: i0, template: "<button type=\"button\" class=\"dynamic-btn dynamic-btn-primary dynamic-margin-vertical-small\" (click)=\"showCodeEditor()\">\n    <span>Edit rich text block</span>\n</button>", changeDetection: i0.ChangeDetectionStrategy.OnPush });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: RichTextBlockPropertiesControlSAComponent, decorators: [{
            type: Component,
            args: [{ selector: 'rich-text-block-properties-control', standalone: true, imports: [], changeDetection: ChangeDetectionStrategy.OnPush, template: "<button type=\"button\" class=\"dynamic-btn dynamic-btn-primary dynamic-margin-vertical-small\" (click)=\"showCodeEditor()\">\n    <span>Edit rich text block</span>\n</button>" }]
        }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }, { type: i1.LayoutEditorMetadataExtractor }, { type: i2.TitledDialogService }] });
//# sourceMappingURL=richTextBlockPropertiesControl.component.js.map