"use strict";
/**
 * React-Compatible Logger Adapter
 *
 * This file provides a React-compatible logger implementation
 * with local logging functionality.
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.logger = exports.ComponentLogger = exports.LogLevel = void 0;
exports.createReactLogger = createReactLogger;
exports.useLogger = useLogger;
const react_1 = __importDefault(require("react"));
// Local LogLevel enum
var LogLevel;
(function (LogLevel) {
    LogLevel["DEBUG"] = "debug";
    LogLevel["INFO"] = "info";
    LogLevel["WARN"] = "warn";
    LogLevel["ERROR"] = "error";
})(LogLevel || (exports.LogLevel = LogLevel = {}));
// Simple logger implementation
class SimpleLogger {
    constructor() {
        this.level = LogLevel.INFO;
    }
    setLevel(level) {
        this.level = level;
    }
    getLevel() {
        return this.level;
    }
    debug(message, data) {
        console.debug(message, data);
    }
    info(message, data) {
        console.info(message, data);
    }
    warn(message, data) {
        console.warn(message, data);
    }
    error(message, error, data) {
        console.error(message, error, data);
    }
}
/**
 * Create a React-compatible logger with local implementation
 */
function createReactLogger(options = {}) {
    const simpleLogger = new SimpleLogger();
    return {
        debug(message, data) {
            simpleLogger.debug(message, formatLogData(data, options.component));
        },
        info(message, data) {
            simpleLogger.info(message, formatLogData(data, options.component));
        },
        warn(message, data) {
            simpleLogger.warn(message, formatLogData(data, options.component));
        },
        error(message, error, data) {
            // Format error data differently to capture error details
            const errorData = {
                ...(data || {}),
                error: error?.message || error,
                stack: error?.stack,
                component: options.component
            };
            simpleLogger.error(message, errorData);
        },
        setLevel(level) {
            simpleLogger.setLevel(level);
        },
        getLevel() {
            return simpleLogger.getLevel();
        }
    };
}
/**
 * Format log data with component context if available
 */
function formatLogData(data, component) {
    if (!data && !component)
        return undefined;
    return {
        ...(data || {}),
        ...(component ? { component } : {})
    };
}
/**
 * Component logger for React components
 */
class ComponentLogger {
    constructor(componentName, options = {}) {
        this.component = componentName;
        this.logger = createReactLogger({
            ...options,
            component: componentName
        });
    }
    debug(message, data) {
        this.logger.debug(message, data);
    }
    info(message, data) {
        this.logger.info(message, data);
    }
    warn(message, data) {
        this.logger.warn(message, data);
    }
    error(message, error, data) {
        this.logger.error(message, error, data);
    }
    setLevel(level) {
        this.logger.setLevel(level);
    }
    getLevel() {
        return this.logger.getLevel();
    }
}
exports.ComponentLogger = ComponentLogger;
/**
 * React hook for using logger in functional components
 */
function useLogger(componentName, options = {}) {
    // Create a stable reference to avoid re-creating on every render
    const loggerRef = react_1.default.useRef(null);
    if (loggerRef.current === null) {
        loggerRef.current = new ComponentLogger(componentName, options);
    }
    return loggerRef.current;
}
// Create default logger instance
exports.logger = createReactLogger({
    service: 'bfui',
    level: (process.env.NODE_ENV === 'development' ? 'debug' : 'info'),
    environment: process.env.NODE_ENV || 'production',
    pretty: process.env.NODE_ENV === 'development'
});
// For compatibility with existing code
exports.default = exports.logger;
//# sourceMappingURL=logger-adapter.js.map