
/*
 * HIGH QUALITY DOORS & WELDING, LLC.
 * Efecto de chispas al hacer clic
 */

document.addEventListener('DOMContentLoaded', function () {

    if (!window.matchMedia(
        '(hover: hover) and (pointer: fine)'
    ).matches) {
        return;
    }

    if (window.matchMedia(
        '(prefers-reduced-motion: reduce)'
    ).matches) {
        return;
    }

    document.addEventListener('pointerdown', function (event) {

        if (event.pointerType !== 'mouse') {
            return;
        }

        const colors = [
            '#ffac23',
            '#ff6b00',
            '#ffd700',
            '#ffffff'
        ];

        for (let i = 0; i < 16; i++) {

            const spark = document.createElement('span');

            spark.className = 'hqdw-spark';

            spark.style.left = event.clientX + 'px';
            spark.style.top = event.clientY + 'px';

            spark.style.background =
                colors[Math.floor(Math.random() * colors.length)];

            const angle = Math.random() * Math.PI * 2;
            const distance = 20 + Math.random() * 55;

            spark.style.setProperty(
                '--dx',
                Math.cos(angle) * distance + 'px'
            );

            spark.style.setProperty(
                '--dy',
                Math.sin(angle) * distance + 'px'
            );

            document.body.appendChild(spark);

            spark.addEventListener('animationend', function () {
                spark.remove();
            }, { once: true });
        }

    });
});
