import { UMB_EDIT_DOCUMENT_WORKSPACE_PATH_PATTERN } from '../paths.js';
import { UMB_DOCUMENT_TABLE_COLLECTION_VIEW_ALIAS } from './constants.js';
import { UmbDefaultCollectionContext } from '../../../core/collection/index.js';
import { UMB_VARIANT_CONTEXT } from '../../../core/variant/index.js';
import { UmbStringState } from '../../../../libs/observable-api/index.js';
import { UmbDeprecation } from '../../../core/utils/index.js';
export class UmbDocumentCollectionContext extends UmbDefaultCollectionContext {
    #variantContext;
    #displayCulture = new UmbStringState(undefined);
    #displayCultureObservable = this.#displayCulture.asObservable();
    constructor(host) {
        super(host, UMB_DOCUMENT_TABLE_COLLECTION_VIEW_ALIAS);
        this.consumeContext(UMB_VARIANT_CONTEXT, async (variantContext) => {
            this.#variantContext = variantContext;
            this.#observeDisplayCulture();
        });
    }
    #observeDisplayCulture() {
        this.observe(this.#variantContext?.displayCulture, (displayCulture) => {
            if (!displayCulture)
                return;
            if (this.#displayCulture.getValue() === displayCulture)
                return;
            this.#displayCulture.setValue(displayCulture);
            this.setFilter({ orderCulture: displayCulture });
        }, 'umbDocumentCollectionDisplayCultureObserver');
    }
    /**
     * Requests the collection from the repository.
     * @returns {Promise<void>}
     * @deprecated Deprecated since v.17.0.0. Use `loadCollection` instead.
     * @memberof UmbDocumentCollectionContext
     */
    async requestCollection() {
        new UmbDeprecation({
            removeInVersion: '19.0.0',
            deprecated: 'requestCollection',
            solution: 'Use .loadCollection method instead',
        }).warn();
        return this._requestCollection();
    }
    async _requestCollection() {
        await this.observe(this.#displayCultureObservable)?.asPromise();
        await super._requestCollection();
    }
    /**
     * Returns the href for a specific Document collection item.
     * @param {UmbDocumentCollectionItemModel} item - The document item to get the href for.
     * @returns {Promise<string | undefined>} - The edit workspace href for the document.
     */
    async requestItemHref(item) {
        return `${UMB_EDIT_DOCUMENT_WORKSPACE_PATH_PATTERN.generateAbsolute({ unique: item.unique })}`;
    }
}
export { UmbDocumentCollectionContext as api };
