import { UmbArrayState } from '../../../libs/observable-api/index.js';
import { UmbStoreBase } from '../../core/store/index.js';
import { UmbContextToken } from '../../../libs/context-api/index.js';
export const UMB_TAG_STORE_CONTEXT_ALIAS = 'UMB_TAG_STORE';
export const UMB_TAG_STORE_CONTEXT = new UmbContextToken(UMB_TAG_STORE_CONTEXT_ALIAS);
/**
 * @class UmbTagStore
 * @augments {UmbStoreBase}
 * @description - Data Store for Template Details
 */
export class UmbTagStore extends UmbStoreBase {
    /**
     * Creates an instance of UmbTagStore.
     * @param {UmbControllerHost} host - The controller host for this controller to be appended to
     * @memberof UmbTagStore
     */
    constructor(host) {
        super(host, UMB_TAG_STORE_CONTEXT.toString(), new UmbArrayState([], (x) => x.id));
        this.data = this._data.asObservable();
    }
    /**
     * Append a tag to the store
     * @param {TagResponseModel} TAG
     * @param tag
     * @memberof UmbTagStore
     */
    append(tag) {
        this._data.append([tag]);
    }
    /**
     * Append a tag to the store
     * @param {id} TagResponseModel id.
     * @param id
     * @memberof UmbTagStore
     */
    byId(id) {
        return this._data.asObservablePart((x) => x.find((y) => y.id === id));
    }
    items(group, culture) {
        return this._data.asObservablePart((items) => items.filter((item) => item.group === group && item.culture === culture));
    }
    // TODO
    // There isnt really any way to exclude certain tags when searching for suggestions.
    // This is important for the skip/take in the endpoint. We do not want to get the tags from database that we already have picked.
    // Forexample: we have 10 different tags that includes "berry" (and searched for "berry") and we have a skip of 0 and take of 5.
    // If we already has picked lets say 4 of them, the list will only show 1 more, even though there is more remaining in the database.
    byQuery(group, culture, query) {
        return this._data.asObservablePart((items) => items.filter((item) => item.group === group &&
            item.culture === culture &&
            item.query?.toLocaleLowerCase().includes(query.toLocaleLowerCase())));
    }
    /**
     * Removes tag in the store with the given uniques
     * @param {string[]} uniques
     * @memberof UmbTagStore
     */
    remove(uniques) {
        this._data.remove(uniques);
    }
}
export default UmbTagStore;
