<script>
  import { createEventDispatcher } from 'svelte';

  import Home from './Home.svelte'
  import DDA from './algorithms/line-drawing/DDA.svelte'
  import Bresenham from './algorithms/line-drawing/Bresenham.svelte'

  const dispatch = createEventDispatcher();

  const pageHome = () => {dispatch('message', { page: Home });}
  const pageDDA = () => {dispatch('message', { page: DDA });}
  const pageBresenham = () => {dispatch('message', { page: Bresenham });}
</script>

<nav class="ddmenu">
  <button on:click={pageHome}>Home</button>

  <div class="ddgroup">
    Line Drawing Algorithms
    <div class="ddsub">
      <button on:click={pageDDA}>DDA</button>
      <button on:click={pageBresenham}>Bresenham</button>
    </div>
  </div>
</nav>

<style>
  .ddmenu { display: flex; }

  .ddmenu button, .ddmenu .ddgroup {
    text-align: left;
    width: 100%;
    padding: 15px;
    color: var(--fg-main);
    text-decoration: none;
    background: var(--bg-alt);
    border: 2px solid var(--bg-main);
  }
  .ddmenu button:hover, .ddmenu .ddgroup:hover {
    color: var(--fg-special-cold);
    background: var(--bg-dim);
    cursor: pointer;
  }
  .ddmenu .ddgroup { position: relative; }
  .ddsub {
    width: 100%;
    position: absolute;
    top: 100%; left: 0;
    display: none;
  }
  .ddsub button {
    display: block;
    box-sizing: border-box;
  }
  .ddgroup:hover .ddsub { display: block; }
  .ddgroup::after {
    content: "\27A4";
    position: absolute;
    top: 13px; right: 10px;
    transition: transform 0.2s;
  }
  .ddgroup:hover::after {
    transform: rotate(90deg);
  }
  @media screen and (max-width: 640px) {
    .ddmenu { flex-wrap: wrap; }
    .ddsub {
      position: static;
      margin-top: 10px;
    }
  }
</style>
