import { UMB_TEMPLATE_ENTITY_TYPE } from '../entity.js';
import { TemplateService } from '../../../core/backend-api/index.js';
import { tryExecute } from '../../../core/resources/index.js';
/**
 * A data source for the Rollback that fetches data from the server
 * @class UmbTemplateSearchServerDataSource
 * @implements {RepositoryDetailDataSource}
 */
export class UmbTemplateSearchServerDataSource {
    #host;
    /**
     * Creates an instance of UmbTemplateSearchServerDataSource.
     * @param {UmbControllerHost} host - The controller host for this controller to be appended to
     * @memberof UmbTemplateSearchServerDataSource
     */
    constructor(host) {
        this.#host = host;
    }
    /**
     * Get a list of versions for a data
     * @param args
     * @returns {*}
     * @memberof UmbTemplateSearchServerDataSource
     */
    async search(args) {
        const { data, error } = await tryExecute(this.#host, TemplateService.getItemTemplateSearch({
            query: {
                query: args.query,
                skip: args.paging?.skip,
                take: args.paging?.take,
            },
        }));
        if (data) {
            const mappedItems = data.items.map((item) => {
                return {
                    href: 'section/settings/workspace/template/edit/' + item.id,
                    entityType: UMB_TEMPLATE_ENTITY_TYPE,
                    unique: item.id,
                    name: item.name,
                    alias: item.alias,
                };
            });
            return { data: { items: mappedItems, total: data.total } };
        }
        return { error };
    }
}
