import { UMB_PACKAGE_STORE_TOKEN } from './package.store.context-token.js';
import { ReplaySubject } from '../../../../external/rxjs/index.js';
import { UmbArrayState, UmbObjectState } from '../../../../libs/observable-api/index.js';
import { UmbStoreBase } from '../../../core/store/index.js';
/**
 * Store for Packages
 * @augments {UmbStoreBase}
 */
export class UmbPackageStore extends UmbStoreBase {
    #configuration;
    /**
     * Array of packages with extensions
     * @private
     */
    // TODO: Revisit this code, to not use RxJS directly:
    #packages;
    #extensions;
    #migrations;
    /**
     * Creates an instance of PackageStore.
     * @param {UmbControllerHost} host - The controller host for this controller to be appended to
     * @memberof PackageStore
     */
    constructor(host) {
        // TODO: revisit this store. Is it ok to have multiple data sets?
        // temp hack to satisfy the base class
        super(host, UMB_PACKAGE_STORE_TOKEN.toString(), new UmbArrayState([], (x) => x.name));
        this.#configuration = new UmbObjectState({ marketplaceUrl: '' });
        /**
         * Array of packages with extensions
         * @private
         */
        // TODO: Revisit this code, to not use RxJS directly:
        this.#packages = new ReplaySubject(1);
        this.#extensions = new UmbArrayState([], (e) => e.alias);
        this.#migrations = new UmbArrayState([], (e) => e.packageName);
        this.configuration = this.#configuration.asObservable();
        /**
         * Observable of packages with extensions
         */
        this.rootItems = this.#packages.asObservable();
        this.extensions = this.#extensions.asObservable();
        this.migrations = this.#migrations.asObservable();
        this.isPackagesLoaded = false;
    }
    /**
     * Append items to the store
     * @param packages
     */
    appendItems(packages) {
        this.#packages.next(packages);
        this.isPackagesLoaded = true;
    }
    appendExtensions(extensions) {
        this.#extensions.append(extensions);
    }
    appendMigrations(migrations) {
        this.#migrations.append(migrations);
    }
    setConfiguration(configuration) {
        this.#configuration.setValue(configuration);
    }
}
export default UmbPackageStore;
