const anime = require('animejs').default;

function wiggle(id, idle) {
    const duration = 300;
    const target = document.getElementById(id);
    const x = window.screen.width * 0.01 * (Math.round(Math.random()) ? Math.random() : -Math.random());
    const y = window.screen.height * 0.01 * (Math.round(Math.random()) ? Math.random() : -Math.random());

    // console.log(x, y);
    return anime({
        targets: target,
        rotate: 0,
        translateX: [x, -x, 0],
        translateY: [y, -y, 0],
        duration,
        easing: 'easeInOutSine',
        // direction: 'alternate',
        begin: idle.pause,
        complete: idle.restart,
    });
}

module.exports = wiggle;
