var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { css, customElement, html, property, state, styleMap } from '../../../external/lit/index.js';
import { UmbChangeEvent, UmbInputEvent } from '../../core/event/index.js';
import { UmbLitElement } from '../../core/lit-element/index.js';
import '../components/code-editor.element.js';
import { UMB_VALIDATION_EMPTY_LOCALIZATION_KEY, UmbFormControlMixin } from '../../core/validation/index.js';
const elementName = 'umb-property-editor-ui-code-editor';
let UmbPropertyEditorUICodeEditorElement = class UmbPropertyEditorUICodeEditorElement extends UmbFormControlMixin(UmbLitElement) {
    #defaultLanguage;
    set config(config) {
        if (!config)
            return;
        const language = config?.getValueByAlias('language');
        this._language = Array.isArray(language) ? language[0] : language;
        this._height = Number(config?.getValueByAlias('height')) || 400;
        this._lineNumbers = config?.getValueByAlias('lineNumbers') ?? false;
        this._minimap = config?.getValueByAlias('minimap') ?? false;
        this._wordWrap = config?.getValueByAlias('wordWrap') ?? false;
    }
    #onChange(event) {
        if (!(event instanceof UmbInputEvent))
            return;
        this.value = event.target.code;
        this.dispatchEvent(new UmbChangeEvent());
    }
    constructor() {
        super();
        this.#defaultLanguage = 'javascript';
        this._language = this.#defaultLanguage;
        this._height = 400;
        this._lineNumbers = true;
        this._minimap = true;
        this._wordWrap = false;
        this.mandatoryMessage = UMB_VALIDATION_EMPTY_LOCALIZATION_KEY;
        this.addValidator('valueMissing', () => this.mandatoryMessage, () => !!this.mandatory && (!this.value || this.value.length === 0));
    }
    render() {
        return html `
			<umb-code-editor
				style=${styleMap({ height: `${this._height}px` })}
				.language=${this._language ?? this.#defaultLanguage}
				.code=${this.value ?? ''}
				?disable-line-numbers=${!this._lineNumbers}
				?disable-minimap=${!this._minimap}
				?word-wrap=${this._wordWrap}
				@input=${this.#onChange}>
			</umb-code-editor>
		`;
    }
    static { this.styles = [
        css `
			umb-code-editor {
				border-radius: var(--uui-border-radius);
				border: 1px solid var(--uui-color-divider-emphasis);
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbPropertyEditorUICodeEditorElement.prototype, "_language", void 0);
__decorate([
    state()
], UmbPropertyEditorUICodeEditorElement.prototype, "_height", void 0);
__decorate([
    state()
], UmbPropertyEditorUICodeEditorElement.prototype, "_lineNumbers", void 0);
__decorate([
    state()
], UmbPropertyEditorUICodeEditorElement.prototype, "_minimap", void 0);
__decorate([
    state()
], UmbPropertyEditorUICodeEditorElement.prototype, "_wordWrap", void 0);
__decorate([
    property({ type: String })
], UmbPropertyEditorUICodeEditorElement.prototype, "mandatoryMessage", void 0);
__decorate([
    property({ attribute: false })
], UmbPropertyEditorUICodeEditorElement.prototype, "config", null);
UmbPropertyEditorUICodeEditorElement = __decorate([
    customElement(elementName)
], UmbPropertyEditorUICodeEditorElement);
export { UmbPropertyEditorUICodeEditorElement };
export { UmbPropertyEditorUICodeEditorElement as element };
