

import React, { useEffect } from "react";
import {Snap} from "./../../../effects/snap.svg-min.js"
import { Link } from "react-router-dom";

interface window {
    Snap:any
}

class SVGMenu {
    private el:HTMLElement;
    private trigger:HTMLElement;
    private pathEl:any;
    private paths:any;
    private  isOpen:boolean;
    private shapeEl;

    constructor( el:HTMLElement ) {
        this.el = el;
        this.init();
    }
    init() {
        
        this.trigger = this.el.querySelector( 'button.menu__handle' );
        this.shapeEl = this.el.querySelector( 'div.morph-shape' );
        const Snap = window.Snap;
console.log(Snap)
        var s = Snap( this.shapeEl.querySelector( 'svg' ) );
        this.pathEl = s.select( 'path' );
        this.paths = {
            reset : this.pathEl.attr( 'd' ),
            open : this.shapeEl.getAttribute( 'data-morph-open' ),
            close : this.shapeEl.getAttribute( 'data-morph-close' )
        };

        this.isOpen = false;

        this.initEvents();
    };

    initEvents() {
        this.trigger.addEventListener( 'click', this.toggle.bind(this) );
    };
    toggle() {
        var self = this;
        if( this.isOpen ) {			
            self.el.classList.remove("menu--anim");
            setTimeout(function(){
                self.el.classList.remove("menu--open");
            }, 250);
        }
        else {
            //classie.add( self.el, 'menu--anim' );
            self.el.classList.add("menu--anim");
            //setTimeout( function() { classie.add( self.el, 'menu--open' );	}, 250 );
            setTimeout(function(){
                self.el.classList.add("menu--open");
            }, 250);
        }
        this.pathEl.stop().animate( { 'path' : this.isOpen ? this.paths.close : this.paths.open }, 350, mina.easeout, function() {
            self.pathEl.stop().animate( { 'path' : self.paths.reset }, 800, mina.elastic );
        } );
        
        this.isOpen = !this.isOpen;
    };

}


export default function MorphingMenu() {
    
    useEffect(()=>{
				SVGMenu.prototype.initEvents = function() {
					this.trigger.addEventListener( 'click', this.toggle.bind(this) );
				};

				new SVGMenu( document.getElementById( 'menu' ) );
    }, [])

        return <>
        <div className="container  absolute top-4 left-0 w-32 h-full">
			<nav id="menu" className="menu ">
				<button className="menu__handle"><span>Menu</span></button>
				<div className="menu__inner h-screen flex justify-end gap-2">
					<ul  style={{display:"flex", flexDirection:"column"}} className="bg-orange-800/75 backdrop-blur mix-blend-darken border shadow-3xl w-full font-bold text-3xl text-gray-100 rounded-2xl  -translate-x-8 flex flex-col gap-4 justify-center items-center text-start">
						<li style={{marginBottom:0}} className="hover:text-red-600 hover:border-b my-0 mb-0  border-red-600 transition-all duration-500">
                            <Link to="/" >
                            <span>Accueil</span>
                            </Link>
                        </li>
						<li style={{marginBottom:0}}  className="hover:text-red-600 -translate-y-32 hover:border-b border-red-600 transition-all duration-500"><Link to="/activite" >
                            <span>Activité</span></Link>
                        </li>
						
						<li style={{marginBottom:0}}  className="hover:text-red-600 hover:border-b border-red-600 transition-all duration-500"><Link to="/actualite"  >
                            <span>Actualité</span>
                            </Link>
                        </li>
                        <li style={{marginBottom:0}}  className="hover:text-red-600 hover:border-b border-red-600 transition-all duration-500">
                            <Link to="/about"  >
                            <span>Contact</span>
                            </Link>
                        </li>
                        <li style={{marginBottom:0}} className="hover:text-gray-200 hover:border-b border-red-600 bg-red-600 transition-all duration-500 text-white text-xl rounded px-4 py-2">
                            <a href={location.origin+"/login"}  >
                            <span>Connexion</span>
                            </a>
                        </li>
					</ul>
				</div>
				<div className="morph-shape bg-transparent" data-morph-open="M300-10c0,0,295,164,295,410c0,232-295,410-295,410" data-morph-close="M300-10C300-10,5,154,5,400c0,232,295,410,295,410">
					<svg width="100%" height="100%" viewBox="0 0 600 800" preserveAspectRatio="none">
						<path fill="none" d="M300-10c0,0,0,164,0,410c0,232,0,410,0,410"/>
					</svg>
				</div>
			</nav>
			<div className="main">
				
			
				
			</div>
		</div>
        </>
}