"use strict";
/*
 * @adonisjs/view
 *
 * (c) Harminder Virk <virk@adonisjs.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.defineAssetsManagerBindings = void 0;
const edge_error_1 = require("edge-error");
/**
 * Registers the asset manager tags and globals with the template engine
 */
function defineAssetsManagerBindings(View, AssetsManager) {
    View.global('assetsManager', AssetsManager);
    View.global('asset', (filename) => AssetsManager.assetPath(filename));
    View.registerTag({
        tagName: 'entryPointStyles',
        seekable: true,
        block: false,
        compile(parser, buffer, token) {
            /**
             * Ensure an argument is defined
             */
            if (!token.properties.jsArg.trim()) {
                throw new edge_error_1.EdgeError('Missing entrypoint name', 'E_RUNTIME_EXCEPTION', {
                    filename: token.filename,
                    line: token.loc.start.line,
                    col: token.loc.start.col,
                });
            }
            const parsed = parser.utils.transformAst(parser.utils.generateAST(token.properties.jsArg, token.loc, token.filename), token.filename, parser);
            const entrypointName = parser.utils.stringify(parsed);
            buffer.outputExpression(`state.assetsManager.entryPointStyleTags(${entrypointName})`, token.filename, token.loc.start.line, false);
        },
    });
    View.registerTag({
        tagName: 'entryPointScripts',
        seekable: true,
        block: false,
        compile(parser, buffer, token) {
            /**
             * Ensure an argument is defined
             */
            if (!token.properties.jsArg.trim()) {
                throw new edge_error_1.EdgeError('Missing entrypoint name', 'E_RUNTIME_EXCEPTION', {
                    filename: token.filename,
                    line: token.loc.start.line,
                    col: token.loc.start.col,
                });
            }
            const parsed = parser.utils.transformAst(parser.utils.generateAST(token.properties.jsArg, token.loc, token.filename), token.filename, parser);
            const entrypointName = parser.utils.stringify(parsed);
            buffer.outputExpression(`state.assetsManager.entryPointScriptTags(${entrypointName})`, token.filename, token.loc.start.line, false);
        },
    });
}
exports.defineAssetsManagerBindings = defineAssetsManagerBindings;
