import { throttle as th } from './util/throttle.js';
import { debounce as deb } from './util/debounce.js';
const COLORS = {
    TRACE: 'grey',
    DEBUG: 'cyan',
};
function logMethod(name, key, args, level) {
    const color = COLORS[level];
    console.log(`[%c${level}%c] %c${name}%c.%c${key}%c(`, `color: ${color}`, 'color: inherit', 'color: #03a9f4', 'color: white', 'color: #03a9f4', 'color: inherit', ...args, ')');
}
function logDecoratorFactory(level) {
    return function log(target, key, descriptor) {
        if (!descriptor) {
            return;
        }
        const originalMethod = descriptor.value;
        descriptor.value = function (...args) {
            logMethod(target.constructor.name, key, args, level);
            return originalMethod.apply(this, arguments);
        };
        return descriptor;
    };
}
export const trace = logDecoratorFactory('TRACE');
export const debug = logDecoratorFactory('DEBUG');
export function deprecated(message) {
    return (target, key, descriptor) => {
        if (!descriptor) {
            return;
        }
        const originalMethod = descriptor.value;
        descriptor.value = function (...args) {
            console.warn(`${key} is deprecated`, message);
            return originalMethod.apply(this, arguments);
        };
        return descriptor;
    };
}
export function throttle(delay, immediate = false) {
    return (target, key, descriptor) => {
        if (!descriptor) {
            return;
        }
        return {
            configurable: true,
            enumerable: descriptor.enumerable,
            get: function getter() {
                // Attach this function to the instance (not the class)
                Object.defineProperty(this, key, {
                    configurable: true,
                    enumerable: descriptor.enumerable,
                    value: th(descriptor.value, delay, immediate),
                });
                return this[key];
            },
        };
    };
}
export function debounce(delay) {
    return (target, key, descriptor) => {
        if (!descriptor) {
            return;
        }
        return {
            configurable: true,
            enumerable: descriptor.enumerable,
            get: function getter() {
                // Attach this function to the instance (not the class)
                Object.defineProperty(this, key, {
                    configurable: true,
                    enumerable: descriptor.enumerable,
                    value: deb(descriptor.value.bind(this), delay),
                });
                return this[key];
            },
        };
    };
}
//# sourceMappingURL=decorators.js.map