<style>
	#plusko {
		align-items: center;
		justify-content: center;
		display: flex;
		cursor: pointer;
		line-height: 1em;
	}
	#plusko:hover {
	}
	#container {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 100vh;
		width: 100vw;
	}
	#dots {
		position: absolute;
		height: 100vh;
		width: 100vw;
	}
	.label {
		position: absolute;
		font-size: calc(var(--font-size) / 1.7);
		transition: .2s ease;
	}
	.label2:hover {
		border: solid 0.1em #d73648;
	}
	.labels:hover > *:not(:hover) {
		font-size: 0.45em;
	}
	.label a {
		color: #000;
	}
	.label2 a:hover {
		color: #d73648;
		opacity: 1 !important;
	}
	.label span:hover ~ .cross {
		display: none;
	}
	#cinnosti {
		left: auto;
		right: auto;
		top: 70vh;
	}
	#predseda {
		left: 23vw;
		top: 15vh;
	}
	#prebiram {
		left: 65vw;
		top: 19vh;
	}
	#zapojit {
		left: 25vw;
		top: 50vh;
	}
	#zalozit {
		top: 60vh;
		left: 71vw;
	}
	#oborovky {
		left: 32vw;
		top: 75vh;
	}
	.active {
	}
	.cross {
	   width: 0.7em;
	   height: 0.7em;
	   position: relative;
	}

	.cross:before, .cross:after {
	  content: "";
	  position: absolute;
	  z-index: -1;
	  background: #d73648;
	}

	.cross:before {
	  left: 50%;
	  width: 10%;
	  margin-left: -5%;
	  height: 100%;
	}

	.cross:after {
	  top: 50%;
	  height: 10%;
	  margin-top: -5%;
	  width: 100%;
	}
	.bottom-right {
		position: absolute;
		right: 0;
		bottom: 0;
		margin-left: 90%;
		margin-top: 5%;
	}
	.top-right {
		position: absolute;
		right: 0;
		top: 0;
		margin-left: 90%;
		margin-bottom: 5%;
	}
	.bottom-left {
		position: absolute;
		left: 0;
		bottom: 0;
		margin-right: 110%;
		margin-top: 5%;
	}
	.top-left {
		position: absolute;
		left: 0;
		top: 0;
		margin-right: 110%;
		margin-bottom: 5%;
	}
	.pedftext {
		position: absolute;
		font-size: calc(var(--font-size) / 1.7);
		left: 5vw;
		bottom: 5vh;
		line-height: 1;
		margin-bottom: 0;
	}
@-webkit-keyframes rotating /* Safari and Chrome */ {
  from {
    -webkit-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@keyframes rotating {
  from {
    -ms-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -webkit-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  to {
    -ms-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -webkit-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}	.spinny {
		opacity: 0;
    }

    #plusko:hover .spinny {
    	opacity: 1;
		animation: rotating 2s linear infinite;
	}
	#plusko:hover .not-spinny {
		opacity: 0;
	}
</style>

<script>
	import Logo from '../components/logo.svelte';
	import anime from 'animejs/lib/anime.es.js';
	import { onMount, afterUpdate } from 'svelte';

	let clicked = false;
	//function drawLineXY(fromXY, toXY) {
	//    if(!lineElem) {
	//        lineElem = document.createElement('canvas');
	//        lineElem.style.position = "absolute";
	//        lineElem.style.zIndex = -100;
	//        document.body.appendChild(lineElem);
	//    }
	//    var leftpoint, rightpoint;
	//    if(fromXY.x < toXY.x) {
	//      leftpoint = fromXY;
	//      rightpoint = toXY;
	//    } else {
	//      leftpoint = toXY;
	//      rightpoint = fromXY;
	//    }

	//    var lineWidthPix = 4;
	//    var gutterPix = 10;
	//    var origin = {x:leftpoint.x-gutterPix, 
	//                  y:Math.min(fromXY.y, toXY.y)-gutterPix};
	//    lineElem.width = Math.max(rightpoint.x - leftpoint.x, lineWidthPix) + 
	//      2.0*gutterPix;
	//    lineElem.height = Math.abs(fromXY.y - toXY.y) + 2.0*gutterPix;
	//    lineElem.style.left = origin.x;
	//    lineElem.style.top = origin.y;
	//    var ctx = lineElem.getContext('2d');
	//    // Use the identity matrix while clearing the canvas
	//    ctx.save();
	//    ctx.setTransform(1, 0, 0, 1, 0, 0);
	//    ctx.clearRect(0, 0, lineElem.width, lineElem.height);
	//    ctx.restore();
	//    ctx.lineWidth = 4;
	//    ctx.strokeStyle = '#09f';
	//    ctx.beginPath();
	//    ctx.moveTo(fromXY.x - origin.x, fromXY.y - origin.y);
	//    ctx.lineTo(toXY.x - origin.x, toXY.y - origin.y);
	//    ctx.stroke();
	//}
	function spin() {
		//anime({
		//	targets: "#plusko img",
		//	rotate: {
		//		value: "+=180",
		//		duration: 300,
		//		direction: "alternate",
		//	},
		//})
	}

	function unspin() {
		//anime({
		//	targets: "#plusko img",
		//	rotate: {
		//		value: 0
		//	}
		//});
	}

	function clicked_fun() {
		clicked = !clicked;

		if (clicked) {
    	}
	}

    function getOffset( el ) {
    	console.log(el);
        var rect = el.getBoundingClientRect();
        return {
            left: rect.left + window.pageXOffset,
            top: rect.top + window.pageYOffset,
            width: rect.width || el.offsetWidth,
            height: rect.height || el.offsetHeight
        };
    }

    function connect(div1, div2, color, thickness) { // draw a line connecting elements
        var off1 = getOffset(div1);
        var off2 = getOffset(div2);
        // bottom right
        var x1 = off1.left + off1.width;
        var y1 = off1.top + off1.height;
        // top right
        var x2 = off2.left + off2.width;
        var y2 = off2.top;
        // distance
        var length = Math.sqrt(((x2-x1) * (x2-x1)) + ((y2-y1) * (y2-y1)));
        // center
        var cx = ((x1 + x2) / 2) - (length / 2);
        var cy = ((y1 + y2) / 2) - (thickness / 2);
        // angle
        var angle = Math.atan2((y1-y2),(x1-x2))*(180 / Math.PI);
        // make hr
        var htmlLine = "<div style='padding:0px; margin:0px; height:" + thickness + "px; background-color:" + color + "; line-height:1px; position:absolute; left:" + cx + "px; top:" + cy + "px; width:" + length + "px; -moz-transform:rotate(" + angle + "deg); -webkit-transform:rotate(" + angle + "deg); -o-transform:rotate(" + angle + "deg); -ms-transform:rotate(" + angle + "deg); transform:rotate(" + angle + "deg);' />";// "
        /**/
        // alert(htmlLine);
        document.body.innerHTML += htmlLine;
    }
	//afterUpdate(() => {
	//	if (document.getElementById("predseda") !== null && document.getElementById("predseda") !== undefined) {
    //		let predseda = document.getElementById("predseda");
    //		let prebiram = document.getElementById("prebiram");
    //		let zapojit = document.getElementById("zapojit");
    //		let zalozit = document.getElementById("zalozit");
    //		let oborovky = document.getElementById("oborovky");
    //		let plusko = document.getElementById("plusko")

    //		connect(predseda, plusko, "#000", "1");
    //		connect(prebiram, plusko, "#000", "1");
    //		connect(zapojit, plusko, "#000", "1");
    //		connect(zalozit, plusko, "#000", "1");
    //		connect(oborovky, plusko, "#000", "1");
	//	}
	//});
    function vwTOpx(value) {
        var w = window,
          d = document,
          e = d.documentElement,
          g = d.getElementsByTagName('body')[0],
          x = w.innerWidth || e.clientWidth || g.clientWidth,
          y = w.innerHeight|| e.clientHeight|| g.clientHeight;

        var result = (x*value) / 100;
        document.getElementById("result_vw_px").innerHTML = result;  // affichage du résultat (facultatif) 
        return result;
      }

      function vhTOpx(value) {
        var w = window,
          d = document,
          e = d.documentElement,
          g = d.getElementsByTagName('body')[0],
          x = w.innerWidth || e.clientWidth || g.clientWidth,
          y = w.innerHeight|| e.clientHeight|| g.clientHeight;

        var result = (y*value) / 100;
        return result;
      }
</script>

<svelte:head>
	<title>PedF UK Spolky | </title>
</svelte:head>

<Logo/>

<main id="container">
	<div id="plusko" on:mouseover="{spin}" on:mouseout="{unspin}" class:active="{clicked}" on:click="{clicked_fun}">
    	{#if clicked}
        	<img src="/img/main-btn-active.png">
    	{:else}
    		<div style="position: relative">
        	<img src="/img/main-btn.png" class="not-spinny" style="height:60px; width: 60px">
        	<img src="/img/main-btn-spin.png" style="position:absolute; left:0; top: 0; height: 60px; width: 60px" class="spinny">
    		</div>
    	{/if}
    </div>

	{#if clicked}
	<div class="labels">
		<div class="label label2" id="predseda">
			<span><a href="/predseda">Předseda spolku</a></span>
			<div class="cross bottom-right"></div>
		</div>
		<div class="label label2" id="prebiram">
			<span style="padding-left: 0.5em; padding-right: 0.5em"><a href="/prebiram">Přebírám spolek</a></span>
			<div class="cross bottom-left"></div>
		</div>
		<div class="label label2" id="zapojit">
			<span><a href="/zapojit-se">Chci se zapojit</a></span>
			<div class="cross top-right"></div>
		</div>
		<div class="label label2" id="zalozit">
			<span style="padding-left: 0.5em; padding-right: 0.5em"><a href="/zalozit-spolek">Chci založit spolek</a></span>
			<div class="cross top-left"></div>
		</div>
		<div class="label label2" id="oborovky">
			<span style="padding-left: 0.5em; padding-right: 0.5em"><a href="/oborovky">Chci vědět víc o oborovkách</a></span>
			<div class="cross top-right"></div>
		</div>
	</div>
	{:else }
		<span class="label" id="cinnosti">Činnosti ve spolcích</span>
	{/if}
	<canvas id="dots">
	</canvas>

	<div class="pedftext">
		<p>Pedagogická fakulta</p>
		<b style="color: #d73648">Univerzita Karlova</b>
		<img src="/svg/zobacek.svg" style="width:0.8em; height: 0.8em; position: absolute; left: 0; bottom: 0; margin-left: -0.5em; margin-bottom: -0.5em; fill: #d73648">
	</div>
</main>
