import { __awaiter } from "tslib";
import { Inject, Injectable, Optional } from '@angular/core';
import { LOGGER } from '@anglr/common';
import { LayoutComponentsRegister } from '../layoutComponentsRegister/layoutComponentsRegister.service';
import * as i0 from "@angular/core";
import * as i1 from "../layoutComponentsRegister/layoutComponentsRegister.service";
/**
 * Dynamic relations nodes provider for layout components
 */
export class LayoutComponentsRelationsNodesProvider {
    //######################### constructor #########################
    constructor(_componentsRegister, _logger) {
        this._componentsRegister = _componentsRegister;
        this._logger = _logger;
    }
    //######################### public methods - implementation of DynamicItemLoaderProvider #########################
    /**
     * @inheritdoc
     */
    tryToGet(source) {
        var _a;
        return __awaiter(this, void 0, void 0, function* () {
            //only works with layout components
            if (source.package != 'layout-components') {
                return null;
            }
            (_a = this._logger) === null || _a === void 0 ? void 0 : _a.debug('LayoutComponentsRelationsNodesProvider: trying to get node {{@item}}', { item: { name: source.name, package: source.package } });
            const type = yield this._componentsRegister.getType(source.name);
            if (!type) {
                return null;
            }
            //TODO: add type for return
            const displayName = yield this._componentsRegister.getDisplayName(source.name);
            const scope = yield this._componentsRegister.getScope(source.name);
            const name = yield this._componentsRegister.getComponentName(source.name);
            const packageName = yield this._componentsRegister.getComponentPackage(source.name);
            return {
                default: type,
                displayName,
                scope,
                name,
                package: packageName,
            };
        });
    }
}
LayoutComponentsRelationsNodesProvider.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: LayoutComponentsRelationsNodesProvider, deps: [{ token: i1.LayoutComponentsRegister }, { token: LOGGER, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
LayoutComponentsRelationsNodesProvider.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: LayoutComponentsRelationsNodesProvider });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: LayoutComponentsRelationsNodesProvider, decorators: [{
            type: Injectable
        }], ctorParameters: () => [{ type: i1.LayoutComponentsRegister }, { type: undefined, decorators: [{
                    type: Inject,
                    args: [LOGGER]
                }, {
                    type: Optional
                }] }] });
//# sourceMappingURL=layoutComponentsRelationsNodesProvider.service.js.map