// modules/parallax/index.js
import { Logger } from '../../core/logger.js';
import { registerFrameTask } from '../../core/frameloop.js';

export function init(config = {}) {
    Logger.info('Parallax init');

    const defaultConfig = {
        selector: '[data-parallax]',
        speedAttr: 'data-parallax-speed',
        defaultSpeed: 0.5
    };

    const settings = { ...defaultConfig, ...config };
    const elements = document.querySelectorAll(settings.selector);

    function updateParallax() {
        const scrollY = window.scrollY;
        elements.forEach(el => {
            const speed = parseFloat(el.getAttribute(settings.speedAttr)) || settings.defaultSpeed;
            const offset = scrollY * speed;
            el.style.transform = `translateY(${offset}px)`;
        });
    }

    registerFrameTask('parallax', updateParallax, { autoStart: true });
}
