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 { sortVariants } from '../utils.js';
import { UMB_DOCUMENT_PUBLISHING_WORKSPACE_CONTEXT } from '../publishing/index.js';
import { customElement, html, state } from '../../../../external/lit/index.js';
import { DocumentVariantStateModel } from '../../../core/backend-api/index.js';
import { UmbWorkspaceSplitViewVariantSelectorElement } from '../../../core/workspace/index.js';
let UmbDocumentWorkspaceSplitViewVariantSelectorElement = class UmbDocumentWorkspaceSplitViewVariantSelectorElement extends UmbWorkspaceSplitViewVariantSelectorElement {
    #documentPublishingWorkspaceContext;
    #publishStateLocalizationMap;
    constructor() {
        super();
        this._variantSorter = sortVariants;
        this._variantsWithPendingChanges = [];
        this.#publishStateLocalizationMap = {
            [DocumentVariantStateModel.DRAFT]: 'content_unpublished',
            [DocumentVariantStateModel.PUBLISHED]: 'content_published',
            // TODO: The pending changes state can be removed once the management Api removes this state
            // We only keep it here to make typescript happy
            // We should also make our own state model for this
            [DocumentVariantStateModel.PUBLISHED_PENDING_CHANGES]: 'content_published',
            [DocumentVariantStateModel.NOT_CREATED]: 'content_notCreated',
            [DocumentVariantStateModel.TRASHED]: 'mediaPicker_trashed',
        };
        this.consumeContext(UMB_DOCUMENT_PUBLISHING_WORKSPACE_CONTEXT, (instance) => {
            this.#documentPublishingWorkspaceContext = instance;
            this.#observePendingChanges();
        });
    }
    #observePendingChanges() {
        this.observe(this.#documentPublishingWorkspaceContext?.publishedPendingChanges.variantsWithChanges, (variants) => {
            this._variantsWithPendingChanges = variants || [];
        }, '_observePendingChanges');
    }
    #hasPendingChanges(variant) {
        return this._variantsWithPendingChanges.some((x) => x.variantId.compare(variant));
    }
    #getVariantState(variantOption) {
        let term = this.#publishStateLocalizationMap[variantOption.variant?.state || DocumentVariantStateModel.NOT_CREATED];
        if ((variantOption.variant?.state === DocumentVariantStateModel.PUBLISHED ||
            variantOption.variant?.state === DocumentVariantStateModel.PUBLISHED_PENDING_CHANGES) &&
            this.#hasPendingChanges(variantOption)) {
            term = 'content_publishedPendingChanges';
        }
        return this.localize.term(term);
    }
    _renderVariantDetails(variantOption) {
        return html ` ${this.#getVariantState(variantOption)}`;
    }
};
__decorate([
    state()
], UmbDocumentWorkspaceSplitViewVariantSelectorElement.prototype, "_variantsWithPendingChanges", void 0);
UmbDocumentWorkspaceSplitViewVariantSelectorElement = __decorate([
    customElement('umb-document-workspace-split-view-variant-selector')
], UmbDocumentWorkspaceSplitViewVariantSelectorElement);
export { UmbDocumentWorkspaceSplitViewVariantSelectorElement };
