import { Inject, Injectable, Optional } from '@angular/core';
import { LOGGER } from '@anglr/common';
import { DynamicItemLoader } from '@anglr/dynamic';
import { RELATIONS_NODES_LOADER } from '@anglr/dynamic/relations-editor';
import { LayoutComponentsRegister } from '../layoutComponentsRegister/layoutComponentsRegister.service';
import * as i0 from "@angular/core";
import * as i1 from "../layoutComponentsRegister/layoutComponentsRegister.service";
import * as i2 from "@anglr/dynamic";
/**
 * Dynamic relations types provider for layout components
 */
export class LayoutComponentsRelationsTypesProvider {
    //######################### constructor #########################
    constructor(_componentsRegister, _loader, _logger) {
        this._componentsRegister = _componentsRegister;
        this._loader = _loader;
        this._logger = _logger;
    }
    //######################### public methods - implementation of DynamicItemLoaderProvider #########################
    /**
     * @inheritdoc
     */
    async tryToGet(source) {
        //only works with layout components
        if (source.package != 'layout-components') {
            return null;
        }
        this._logger?.debug('LayoutComponentsRelationsTypesProvider: trying to get relations types {{@item}}', { item: { name: source.name, package: source.package } });
        const types = await this._componentsRegister.types;
        if (!types) {
            return null;
        }
        const resultTypes = [];
        for (const type of types) {
            const node = await this._loader.loadItem({ package: 'layout-components', name: type });
            if (node?.data) {
                resultTypes.push(type);
            }
        }
        return {
            default: resultTypes,
        };
    }
}
LayoutComponentsRelationsTypesProvider.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: LayoutComponentsRelationsTypesProvider, deps: [{ token: i1.LayoutComponentsRegister }, { token: RELATIONS_NODES_LOADER }, { token: LOGGER, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
LayoutComponentsRelationsTypesProvider.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: LayoutComponentsRelationsTypesProvider });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: LayoutComponentsRelationsTypesProvider, decorators: [{
            type: Injectable
        }], ctorParameters: () => [{ type: i1.LayoutComponentsRegister }, { type: i2.DynamicItemLoader, decorators: [{
                    type: Inject,
                    args: [RELATIONS_NODES_LOADER]
                }] }, { type: undefined, decorators: [{
                    type: Inject,
                    args: [LOGGER]
                }, {
                    type: Optional
                }] }] });
//# sourceMappingURL=layoutComponentsRelationsTypesProvider.service.js.map