"use strict";
/*
 * @adonisjs/core
 *
 * (c) AdonisJS
 *
 * 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.BaseRender = void 0;
/**
 * Methods registered by "Route.any" method
 */
const ALL_METHODS = ['HEAD', 'OPTIONS', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
class BaseRender {
    constructor(command) {
        this.command = command;
        /**
         * The colors associated with each HTTP method
         */
        this.methodColors = {
            GET: 'cyan',
            POST: 'green',
            PUT: 'yellow',
            PATCH: 'yellow',
            DELETE: 'red',
            HEAD: 'gray',
        };
    }
    /**
     * Returns the color name for a HTTP method
     */
    getHttpMethodColor(method) {
        const methodColor = this.methodColors[method];
        return methodColor ? methodColor : 'gray';
    }
    /**
     * Find if the route contains all the methods registered by
     * the "Route.any" method
     */
    hasAllMethods(methods) {
        return ALL_METHODS.every((method) => methods.includes(method));
    }
    /**
     * Colorize the route methods
     */
    colorizeRouteMethods(methods) {
        return this.hasAllMethods(methods)
            ? this.command.colors.cyan('ANY')
            : methods
                .map((method) => this.command.colors[this.getHttpMethodColor(method)](method))
                .join(this.command.colors.gray('|'));
    }
    /**
     * Colorize the route pattern
     */
    colorizeRoutePattern(pattern) {
        return pattern
            .replace(/:([^/]+)/gm, `${this.command.colors.yellow('$&')}`)
            .replace(/\*/gm, `${this.command.colors.red('$&')}`);
    }
    /**
     * Returns the rendering width.
     */
    getRenderingWidth() {
        return this.command.maxWidth || process.stdout.columns || 80;
    }
}
exports.BaseRender = BaseRender;
