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 { UMB_SCRIPT_WORKSPACE_CONTEXT } from './script-workspace.context-token.js';
import { css, html, customElement, state, nothing } from '../../../../external/lit/index.js';
import { UmbLitElement } from '../../../core/lit-element/index.js';
import '../../../code-editor/index.js';
let UmbScriptWorkspaceEditorElement = class UmbScriptWorkspaceEditorElement extends UmbLitElement {
    #context;
    constructor() {
        super();
        this._content = '';
        this.consumeContext(UMB_SCRIPT_WORKSPACE_CONTEXT, (context) => {
            this.#context = context;
            this.observe(this.#context?.content, (content) => (this._content = content));
            this.observe(this.#context?.isNew, (isNew) => (this._isNew = isNew));
        });
    }
    #onCodeEditorInput(event) {
        const target = event.target;
        const value = target.code;
        this.#context?.setContent(value);
    }
    render() {
        return html `
			<umb-entity-detail-workspace-editor>
				<umb-workspace-header-name-editable
					slot="header"
					?readonly=${this._isNew === false}></umb-workspace-header-name-editable>
				${this.#renderBody()}
			</umb-entity-detail-workspace-editor>
		`;
    }
    #renderBody() {
        return html `
			<uui-box>
				<!-- the div below in the header is to make the box display nicely with code editor -->
				<div slot="header"></div>
				${this.#renderCodeEditor()}
			</uui-box>
		`;
    }
    #renderCodeEditor() {
        if (this._content === undefined) {
            return nothing;
        }
        return html `
			<umb-code-editor
				id="content"
				language="javascript"
				.code=${this._content ?? ''}
				@input=${this.#onCodeEditorInput}></umb-code-editor>
		`;
    }
    static { this.styles = [
        css `
			umb-code-editor {
				--editor-height: calc(100dvh - 260px);
			}

			uui-box {
				min-height: calc(100dvh - 260px);
				margin: var(--uui-size-layout-1);
				--uui-box-default-padding: 0;
				/* remove header border bottom as code editor looks better in this box */
				--uui-color-divider-standalone: transparent;
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbScriptWorkspaceEditorElement.prototype, "_content", void 0);
__decorate([
    state()
], UmbScriptWorkspaceEditorElement.prototype, "_isNew", void 0);
UmbScriptWorkspaceEditorElement = __decorate([
    customElement('umb-script-workspace-editor')
], UmbScriptWorkspaceEditorElement);
export { UmbScriptWorkspaceEditorElement };
export default UmbScriptWorkspaceEditorElement;
