/**
 * Utility functions for common operations
 */
const Helpers = {
    /**
     * Debounces a function
     * @param {Function} func - The function to debounce
     * @param {number} wait - The wait time in milliseconds
     * @returns {Function} The debounced function
     */
    debounce(func, wait) {
        let timeout;
        return function executedFunction(...args) {
            const later = () => {
                clearTimeout(timeout);
                func(...args);
            };
            clearTimeout(timeout);
            timeout = setTimeout(later, wait);
        };
    },

    /**
     * Formats a date string
     * @param {string|Date} date - The date to format
     * @returns {string} The formatted date string
     */
    formatDate(date) {
        if (!date) return '';
        const d = new Date(date);
        return d.toLocaleDateString() + ' ' + d.toLocaleTimeString();
    },

    /**
     * Truncates a string to a specified length
     * @param {string} str - The string to truncate
     * @param {number} length - The maximum length
     * @returns {string} The truncated string
     */
    truncate(str, length) {
        if (!str) return '';
        return str.length > length ? str.substring(0, length) + '...' : str;
    },

    /**
     * Shows a notification message
     * @param {string} message - The message to show
     * @param {string} type - The type of notification (success, error, warning, info)
     */
    showNotification(message, type = 'info') {
        // You can implement your preferred notification system here
        console.log(`[${type.toUpperCase()}] ${message}`);
    }
}; 