"use strict";
/*
 * apidocts
 * https://apidocts.com
 * https://apidoc.app
 * Href Spa API Doc (TypeScript version)
 *
 * Author: Href Spa <hola@apidoc.app>
 * Copyright (c) 2025 Href SpA
 * Licensed under the MIT license.
 *
 * This project is a TypeScript refactor inspired by the original apidoc project.
 */
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 () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLogger = getLogger;
exports.getMarkdownParser = getMarkdownParser;
/**
 * Provide default values for the app
 */
const markdown_it_1 = __importDefault(require("markdown-it"));
const path = __importStar(require("path"));
const winston = __importStar(require("winston"));
/**
 * Create and return a logger instance
 *
 * @param options - Configuration options
 * @param options.logFormat - Log format ('json' or default)
 * @param options.colorize - Enable colorized output
 * @param options.debug - If true, debug level logging
 * @param options.verbose - If true, verbose level logging
 * @param options.silent - If true, disables logging
 * @returns Winston logger instance.
 */
function getLogger(options) {
    // default format
    let format = winston.format.simple();
    if (options.logFormat === 'json') {
        // remove colors for json output
        options.colorize = false;
        format = winston.format.json();
    }
    // add colors (default is true)
    if (options.colorize) {
        format = winston.format.combine(winston.format.colorize(), format);
    }
    // console logger
    return winston.createLogger({
        transports: [
            new winston.transports.Console({
                level: options.debug ? 'debug' : options.verbose ? 'verbose' : 'info',
                silent: options.silent || false,
            }),
        ],
        format: format,
    });
}
/**
 * Get the markdown parser
 *
 * @param options - Configuration options
 * @param options.markdown - Markdown parser behavior:
 *     - `true` to use the default Markdown parser with specific settings.
 *     - `false` to disable parsing.
 *     - A string indicating the path to a custom parser.
 * @returns An instance of the Markdown parser if enabled or configured
 */
function getMarkdownParser(options) {
    // Markdown Parser: enable / disable / use a custom parser.
    let markdownParser = null;
    if (options.markdown === true) {
        const md = new markdown_it_1.default({
            breaks: false,
            html: true,
            linkify: false,
            typographer: false,
            highlight: function (str, lang) {
                if (lang) {
                    return '<pre class="my-4"><code class="language-' + lang + '">' + str + '</code></pre>';
                }
                return '<pre class="my-4"><code>' + str + '</code></pre>';
            },
        });
        markdownParser = {
            render: (content) => md.render(content),
        };
    }
    else if (options.markdown !== false && typeof options.markdown === 'string') {
        // Include custom Parser @see https://github.com/apidoc/apidoc/wiki/Custom-markdown-parser
        let customMarkdownPath = options.markdown;
        if (customMarkdownPath.substring(0, 2) !== '..' &&
            ((customMarkdownPath.substring(0, 1) !== '/' &&
                customMarkdownPath.substring(1, 3) !== ':/' &&
                customMarkdownPath.substring(1, 3) !== ':\\' &&
                customMarkdownPath.substring(0, 1) !== '~') ||
                customMarkdownPath.substring(0, 1) === '.')) {
            customMarkdownPath = path.join(process.cwd(), customMarkdownPath);
        }
        try {
            const CustomMarkdown = require(customMarkdownPath);
            const customMd = new CustomMarkdown();
            markdownParser = {
                render: (content) => {
                    if (typeof customMd.render === 'function') {
                        return customMd.render(content);
                    }
                    else if (typeof customMd === 'function') {
                        return customMd(content);
                    }
                    return content;
                },
            };
        }
        catch (error) {
            console.warn(`Failed to load custom markdown parser from ${customMarkdownPath}:`, error);
        }
    }
    return markdownParser;
}
// For CommonJS compatibility
module.exports = {
    getLogger,
    getMarkdownParser,
};
//# sourceMappingURL=defaults.js.map