class Sigil {
    // Convert string to sigil array
    static generate(str) {
        if (!str) return [];
        
        // Convert to lowercase, remove non-word characters
        const cleaned = str.toLowerCase().replace(/[^a-z]/g, '');
        
        // Remove vowels
        const noVowels = cleaned.replace(/[aeiou]/g, '');
        
        // Remove duplicate characters
        const deduped = [...new Set(noVowels)].join('');
        
        // Convert to ASCII values and get digital roots
        return [...deduped].map(char => {
            const ascii = char.charCodeAt(0);
            return Sigil.getDigitalRoot(ascii);
        });
    }

    // Get digital root of a number (sum digits until single digit)
    static getDigitalRoot(num) {
        if (num < 10) return num;
        return Sigil.getDigitalRoot([...num.toString()].reduce((sum, digit) => sum + parseInt(digit), 0));
    }

    // Helper to validate and debug sigil generation
    static debug(str) {
        console.log({
            original: str,
            lowercase: str.toLowerCase(),
            cleaned: str.toLowerCase().replace(/[^a-z]/g, ''),
            noVowels: str.toLowerCase().replace(/[^a-z]/g, '').replace(/[aeiou]/g, ''),
            deduped: [...new Set(str.toLowerCase().replace(/[^a-z]/g, '').replace(/[aeiou]/g, ''))].join(''),
            sigil: Sigil.generate(str)
        });
    }
}

// Export for use in other files
if (typeof module !== 'undefined' && module.exports) {
    module.exports = Sigil;
} 