"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComponentContext = void 0;
const static_injector_1 = require("static-injector");
const template_1 = require("../../angular-internal/template");
const util_1 = require("../../angular-internal/util");
const i0 = __importStar(require("static-injector"));
class ComponentContext {
    constructor(directiveMatcher) {
        this.directiveMatcher = directiveMatcher;
    }
    matchDirective(node) {
        if (!this.directiveMatcher) {
            return [];
        }
        const name = node.name;
        const selector = (0, template_1.createCssSelector)(name, (0, util_1.getAttrsForDirectiveMatching)(node));
        const result = [];
        this.directiveMatcher.match(selector, (selector, meta) => {
            var _a, _b, _c, _d, _e, _f, _g;
            let item;
            const isComponent = !!meta.directive.isComponent;
            if (isComponent) {
                item = {
                    isComponent,
                    outputs: meta.directive.outputs,
                    filePath: meta.directive.importedFile.fileName,
                    selector: meta.directive.selector,
                    className: meta.directive.ref.node.name.getText(),
                    listeners: Object.keys(((_b = (_a = meta.componentMeta) === null || _a === void 0 ? void 0 : _a.host) === null || _b === void 0 ? void 0 : _b.listeners) || {}) || [],
                    inputs: meta.directive.inputs,
                };
                if ((_c = meta.libraryMeta) === null || _c === void 0 ? void 0 : _c.isComponent) {
                    item.exportPath = meta.libraryMeta.exportPath;
                    item.listeners = meta.libraryMeta.listeners;
                    item.properties = meta.libraryMeta.properties;
                }
            }
            else {
                item = {
                    isComponent,
                    listeners: Object.keys(((_e = (_d = meta.directiveMeta) === null || _d === void 0 ? void 0 : _d.host) === null || _e === void 0 ? void 0 : _e.listeners) || {}) || [],
                    properties: Object.keys(((_g = (_f = meta.directiveMeta) === null || _f === void 0 ? void 0 : _f.host) === null || _g === void 0 ? void 0 : _g.properties) || {}) || [],
                    inputs: meta.directive.inputs,
                    outputs: meta.directive.outputs,
                };
                if (meta.libraryMeta && !meta.libraryMeta.isComponent) {
                    item.listeners = meta.libraryMeta.listeners;
                    item.properties = meta.libraryMeta.properties;
                }
            }
            result.push(item);
        });
        return result;
    }
}
ComponentContext.ɵfac = function ComponentContext_Factory(t) { i0.ɵɵinvalidFactory(); };
ComponentContext.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: ComponentContext, factory: ComponentContext.ɵfac });
exports.ComponentContext = ComponentContext;
