<!--
   Copyright 2018 Brigham Young University

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<template>
  <header>
    <a class="logo" href="/">
      <slot name="logo">
      <img src="/logo.jpg" alt="Logo">
      </slot>
    </a>

    <span class="page-title">
      <slot>Decision Processing</slot>
    </span>

    <span :class="{ tools: true, hidden: !menuOpen }">
      <slot name="search"> </slot>
      <user-info />
    </span>

    <span class="menu-button" @click="menuOpen = !menuOpen">
      <font-awesome-icon :icon="menuIcon" />
    </span>

    <nav :class="{ hidden: !menuOpen }">
      <slot name="nav"></slot>
    </nav>

  </header>
</template>
<script>
  import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
  import { faBars, faTimes } from '@fortawesome/free-solid-svg-icons'
  import UserInfo from './UserInfo'

  export default {
    name: 'Header',
    components: {
      UserInfo,
      FontAwesomeIcon
    },
    data () {
      return {
        menuOpen: false
      }
    },
    computed: {
      menuIcon () {
        return this.menuOpen ? faTimes : faBars
      }
    }
  }
</script>
<style scoped>
  header {
    display: grid;
    grid-template-columns: 2rem auto 1rem 1fr auto 1rem;
    grid-auto-rows: auto;
    grid-template-areas:
    ". logo . title tools ."
    "nav nav nav nav nav nav";
    align-items: center;
  }
  .logo { grid-area: logo; }
  .page-title {
    grid-area: title;
    font-size: 1.5rem;
    text-transform: uppercase;
  }
  .tools {
    grid-area: tools;
    display: grid;
    grid-template-columns: auto auto;
    grid-auto-rows: auto;
    grid-gap: 1rem;
    align-items: center;
  }
  nav {
    grid-area: nav;
    box-shadow: 0rem 0.1rem 0.1rem rgba(0, 0, 0, 0.25);
    flex: 0 0 auto;
  }
  .menu-button { display: none; }

  @media only screen and (max-width: 625px) {
    header {
      grid-template-columns: 2rem auto 1rem 1fr;
      grid-auto-rows: auto;
      grid-template-areas:
      ". logo . title menu-button"
      "nav nav nav nav nav"
      "tools tools tools tools tools";
      box-shadow: 0rem 0.1rem 0.1rem rgba(0, 0, 0, 0.25);
    }
    .menu-button {
      display: inline-block;
      grid-area: menu-button;
      margin: 0 0.5rem;
    }
    .tools {
      padding: 0.5rem;
      background-color: #f7f7f8;
      display: grid;
      grid-template-columns: 1fr;
      grid-auto-rows: auto;
      grid-gap: 0.5rem;
      box-shadow: 0rem 0.1rem 0.1rem rgba(0, 0, 0, 0.25);
    }
    nav {
      box-shadow: none;
    }
    .hidden {
      display: none;
    }
  }

  @media only screen and (max-width: 369px) {
    .page-title { display: none; }
  }
</style>
