/**
 * Utility functions for the 3D Editor.
 */

/**
 * Calculates SHA-256 hash from a File object.
 * @param {File} file 
 * @returns {Promise<string>} Hexadecimal hash string
 */
export const calculateHash = async (file) => {
    const arrayBuffer = await file.arrayBuffer();
    const hashBuffer = await crypto.subtle.digest('SHA-256', arrayBuffer);
    const hashArray = Array.from(new Uint8Array(hashBuffer));
    return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
};

/**
 * Checks if two objects are different (shallow JSON comparison).
 */
export const hasObjectChanges = (obj1, obj2) => {
    return JSON.stringify(obj1) !== JSON.stringify(obj2);
};

/**
 * Checks if an object has actual meaningful content (non-empty values).
 * Ignores empty strings, null, undefined, false, and empty arrays.
 */
export const hasActualContent = (obj) => {
    if (!obj || typeof obj !== 'object') return false;
    
    return Object.values(obj).some(value => {
        if (value === null || value === undefined || value === '' || value === false) return false;
        if (Array.isArray(value) && value.length === 0) return false;
        return true;
    });
};