const preact = require('preact');
const { Component } = require('preact');

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

class Amplify extends Component {
    constructor() {
        super();
        this.id = Math.random();
    }

    render() {
        const path = 'M0,100 C100,100 100,100 200,100';

        return (
            <svg
                class='skill-animation'
                version="1.1"
                id="amplify"
                xmlns="http://www.w3.org/2000/svg"
                viewBox="0 0 200 200">
                <filter id="ampFilter">
                    <feTurbulence type="turbulence" baseFrequency="0.4" numOctaves="2" result="turbulence" style="transform: scale(1);"></feTurbulence>
                    <feDisplacementMap in2="turbulence" in="SourceGraphic" scale="2" xChannelSelector="R" yChannelSelector="G"></feDisplacementMap>
                </filter>
                <path filter='url("#ampFilter")' d={path} />
            </svg>
        );
    }

    componentDidMount() {
        const altPath = 'M0,100 C100,400 100,-200 200,100';
        anime({
            targets: '#amplify path',
            d: [{ value: altPath }],
            stroke: ['#3498db', '#a52a2a'],
            duration: 1000,
            direction: 'alternate',
            easing: 'easeInOutSine',
            delay: 500,
        });

        anime({
            targets: ['#ampFilter feTurbulence', '#ampFilter feDisplacementMap'],
            baseFrequency: 0.15,
            scale: 4,
            direction: 'alternate',
            easing: 'easeInOutExpo',
            delay: 500,
        });
    }
}

module.exports = Amplify;
