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_DOCUMENT_TYPE_WORKSPACE_CONTEXT } from '../../document-type-workspace.context-token.js';
import { UmbDocumentTypeConfigurationRepository } from '../../../../configuration/configuration.repository.js';
import { css, html, customElement, state, when, nothing, } from '../../../../../../../external/lit/index.js';
import { UmbTextStyles } from '../../../../../../core/style/index.js';
import { UmbLitElement } from '../../../../../../core/lit-element/index.js';
let UmbDocumentTypeWorkspaceViewSettingsElement = class UmbDocumentTypeWorkspaceViewSettingsElement extends UmbLitElement {
    #workspaceContext;
    #configurationRepository = new UmbDocumentTypeConfigurationRepository(this);
    constructor() {
        super();
        this.consumeContext(UMB_DOCUMENT_TYPE_WORKSPACE_CONTEXT, (documentTypeContext) => {
            this.#workspaceContext = documentTypeContext;
            this.#observeDocumentType();
        });
    }
    async firstUpdated(_changedProperties) {
        super.firstUpdated(_changedProperties);
        // TODO: cache this request
        const { data } = await this.#configurationRepository.requestConfiguration();
        if (data) {
            this._useSegments = data.useSegments;
        }
    }
    #observeDocumentType() {
        if (!this.#workspaceContext)
            return;
        this.observe(this.#workspaceContext.variesByCulture, (variesByCulture) => (this._variesByCulture = variesByCulture));
        this.observe(this.#workspaceContext.variesBySegment, (variesBySegment) => (this._variesBySegment = variesBySegment));
        this.observe(this.#workspaceContext.isElement, (isElement) => (this._isElement = isElement));
        this.observe(this.#workspaceContext.cleanup, (cleanup) => {
            this._preventCleanup = cleanup?.preventCleanup;
            this._keepAllVersionsNewerThanDays = cleanup?.keepAllVersionsNewerThanDays;
            this._keepLatestVersionPerDayForDays = cleanup?.keepLatestVersionPerDayForDays;
        });
    }
    #setCleanup() {
        this.#workspaceContext?.setCleanup({
            preventCleanup: this._preventCleanup ?? false,
            keepAllVersionsNewerThanDays: this._keepAllVersionsNewerThanDays,
            keepLatestVersionPerDayForDays: this._keepLatestVersionPerDayForDays,
        });
    }
    #onChangePreventCleanup(event) {
        this._preventCleanup = event.target.checked;
        if (this._preventCleanup) {
            this._keepAllVersionsNewerThanDays = null;
            this._keepLatestVersionPerDayForDays = null;
        }
        this.#setCleanup();
    }
    #onChangeKeepAllVersionsNewerThanDays(event) {
        this._keepAllVersionsNewerThanDays = parseInt(event.target.value);
        this.#setCleanup();
    }
    #onChangeKeepLatestVersionPerDayForDays(event) {
        this._keepLatestVersionPerDayForDays = parseInt(event.target.value);
        this.#setCleanup();
    }
    render() {
        return html `
			<uui-box headline="Data variations">
				<umb-property-layout
					alias="VaryByCulture"
					label=${this.localize.term('contentTypeEditor_cultureVariantHeading')}>
					<div slot="description">
						<umb-localize key="contentTypeEditor_cultureVariantDescription"
							>Allow editors to create content of different languages.</umb-localize
						>
					</div>
					<div slot="editor">
						<uui-toggle
							?checked=${this._variesByCulture}
							@change=${(e) => {
            this.#workspaceContext?.setVariesByCulture(e.target.checked);
        }}
							label=${this.localize.term('contentTypeEditor_cultureVariantLabel')}></uui-toggle>
					</div>
				</umb-property-layout>

				${this.#renderVaryBySegmentProperty()}

				<umb-property-layout alias="ElementType" label=${this.localize.term('contentTypeEditor_elementHeading')}>
					<div slot="description">
						<umb-localize key="contentTypeEditor_elementDescription"
							>An Element Type is used for content instances in Property Editors, like the Block Editors.</umb-localize
						>
					</div>
					<div slot="editor">
						<uui-toggle
							?checked=${this._isElement}
							@change=${(e) => {
            this.#workspaceContext?.setIsElement(e.target.checked);
        }}
							label=${this.localize.term('contentTypeEditor_elementType')}></uui-toggle>
					</div>
				</umb-property-layout>
			</uui-box>
			<uui-box headline=${this.localize.term('contentTypeEditor_historyCleanupHeading')}>
				<umb-property-layout
					alias="HistoryCleanup"
					label=${this.localize.term('contentTypeEditor_historyCleanupHeading')}>
					<div slot="description">
						<umb-localize key="contentTypeEditor_historyCleanupDescription"
							>Allow overriding the global history cleanup settings.</umb-localize
						>
					</div>
					<div slot="editor">
						<uui-form-layout-item>
							<uui-toggle
								id="prevent-cleanup"
								label=${this.localize.term('contentTypeEditor_historyCleanupPreventCleanup')}
								.checked=${this._preventCleanup ?? false}
								@change=${this.#onChangePreventCleanup}></uui-toggle>
						</uui-form-layout-item>

						${when(!this._preventCleanup, () => html `
								<uui-form-layout-item>
									<uui-label slot="label" for="versions-newer-than-days">
										<umb-localize key="contentTypeEditor_historyCleanupKeepAllVersionsNewerThanDays"
											>Keep all versions newer than days</umb-localize
										>
									</uui-label>

									<uui-input
										type="number"
										id="versions-newer-than-days"
										min="0"
										placeholder="7"
										.value=${this._keepAllVersionsNewerThanDays?.toString() ?? ''}
										@change=${this.#onChangeKeepAllVersionsNewerThanDays}></uui-input>
								</uui-form-layout-item>

								<uui-form-layout-item>
									<uui-label slot="label" for="latest-version-per-day-days">
										<umb-localize key="contentTypeEditor_historyCleanupKeepLatestVersionPerDayForDays"
											>Keep latest version per day for days</umb-localize
										>
									</uui-label>
									<uui-input
										type="number"
										id="latest-version-per-day-days"
										min="0"
										placeholder="90"
										.value=${this._keepLatestVersionPerDayForDays?.toString() ?? ''}
										@change=${this.#onChangeKeepLatestVersionPerDayForDays}></uui-input>
								</uui-form-layout-item>
							`)}
					</div>
				</umb-property-layout>
			</uui-box>
		`;
    }
    #renderVaryBySegmentProperty() {
        if (!this._useSegments)
            return nothing;
        if (this._isElement)
            return nothing;
        return html `
			<umb-property-layout
				alias="VaryBySegments"
				label=${this.localize.term('contentTypeEditor_segmentVariantHeading')}>
				<div slot="description">
					<umb-localize key="contentTypeEditor_segmentVariantDescription"
						>Allow editors to segment their content.</umb-localize
					>
				</div>
				<div slot="editor">
					<uui-toggle
						?checked=${this._variesBySegment}
						@change=${(e) => {
            this.#workspaceContext?.setVariesBySegment(e.target.checked);
        }}
						label=${this.localize.term('contentTypeEditor_segmentVariantLabel')}></uui-toggle>
				</div>
			</umb-property-layout>
		`;
    }
    static { this.styles = [
        UmbTextStyles,
        css `
			:host {
				display: block;
				margin: var(--uui-size-layout-1);
				padding-bottom: var(--uui-size-layout-1); // To enforce some distance to the bottom of the scroll-container.
			}
			uui-box {
				margin-top: var(--uui-size-layout-1);
			}

			uui-label,
			umb-property-editor-ui-number {
				display: block;
			}

			// TODO: is this necessary?
			uui-toggle {
				display: flex;
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbDocumentTypeWorkspaceViewSettingsElement.prototype, "_variesByCulture", void 0);
__decorate([
    state()
], UmbDocumentTypeWorkspaceViewSettingsElement.prototype, "_variesBySegment", void 0);
__decorate([
    state()
], UmbDocumentTypeWorkspaceViewSettingsElement.prototype, "_isElement", void 0);
__decorate([
    state()
], UmbDocumentTypeWorkspaceViewSettingsElement.prototype, "_keepAllVersionsNewerThanDays", void 0);
__decorate([
    state()
], UmbDocumentTypeWorkspaceViewSettingsElement.prototype, "_keepLatestVersionPerDayForDays", void 0);
__decorate([
    state()
], UmbDocumentTypeWorkspaceViewSettingsElement.prototype, "_preventCleanup", void 0);
__decorate([
    state()
], UmbDocumentTypeWorkspaceViewSettingsElement.prototype, "_useSegments", void 0);
UmbDocumentTypeWorkspaceViewSettingsElement = __decorate([
    customElement('umb-document-type-workspace-view-settings')
], UmbDocumentTypeWorkspaceViewSettingsElement);
export { UmbDocumentTypeWorkspaceViewSettingsElement };
export default UmbDocumentTypeWorkspaceViewSettingsElement;
