"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.analyzeVueComponentFromTemplate = void 0;
const type_analyzer_1 = require("@previewjs/type-analyzer");
const typescript_1 = __importDefault(require("typescript"));
function analyzeVueComponentFromTemplate(typeAnalyzer, absoluteFilePath) {
    // This virtual file exists thanks to transformReader().
    const tsFilePath = `${absoluteFilePath}.ts`;
    const resolver = typeAnalyzer.analyze([tsFilePath]);
    const sourceFile = resolver.sourceFile(tsFilePath);
    for (const statement of (sourceFile === null || sourceFile === void 0 ? void 0 : sourceFile.statements) || []) {
        if (typescript_1.default.isTypeAliasDeclaration(statement) &&
            statement.name.text === "PJS_Props") {
            const type = resolver.checker.getTypeAtLocation(statement);
            const defineComponentProps = resolver.resolveType(type);
            return {
                propsType: defineComponentProps.type,
                types: defineComponentProps.collected,
            };
        }
    }
    return {
        propsType: type_analyzer_1.UNKNOWN_TYPE,
        types: {},
    };
}
exports.analyzeVueComponentFromTemplate = analyzeVueComponentFromTemplate;
