/**
 * Native implementation of debounce function
 * Delays function execution until after a specified wait period has elapsed
 * since the last time it was invoked.
 *
 * @param func - The function to debounce
 * @param wait - The number of milliseconds to delay
 * @returns Debounced function with cancel method
 */
export function debounce(func, wait) {
    let timeout = null;
    const debounced = function (...args) {
        const context = this;
        if (timeout !== null) {
            clearTimeout(timeout);
        }
        timeout = setTimeout(() => {
            timeout = null;
            func.apply(context, args);
        }, wait);
    };
    // Add cancel method to clear pending execution
    debounced.cancel = function () {
        if (timeout !== null) {
            clearTimeout(timeout);
            timeout = null;
        }
    };
    return debounced;
}
/**
 * Native implementation of groupBy function
 * Groups array elements by the result of a key function
 *
 * @param array - The array to group
 * @param keyFn - Function that returns the grouping key for each element
 * @returns Object with keys as group identifiers and values as arrays of grouped elements
 */
export function groupBy(array, keyFn) {
    return array.reduce((result, item) => {
        const key = keyFn(item);
        if (!result[key]) {
            result[key] = [];
        }
        result[key].push(item);
        return result;
    }, {});
}
export function truncateText(text, maxLength) {
    if (text.length > maxLength) {
        return text.slice(0, maxLength) + '...';
    }
    return text;
}
