<!doctype html>

<head>
  <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  <meta content="utf-8" http-equiv="encoding">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="mobile-web-app-capable" content="yes">
  <link rel="icon" sizes="128x128" href="icon.png">
  <link rel="apple-touch-icon" sizes="128x128" href="icon.png">
  <meta name="theme-color" content="#216e51">
  <meta name="apple-mobile-web-app-status-bar-style" content="#216e51">

  <!-- <meta name="theme-color" content="#f7d723">
  <meta name="apple-mobile-web-app-status-bar-style" content="#f7d723"> -->

  <style>
    * {
      margin: 0;
      padding: 0;
    }

    #splash {
      background-color: #216e51;
      color: rgb(207, 207, 207);
      padding: 10%;
      margin: 0%;
      font-size: 4em;
      font-weight: bolder;
      padding-bottom: 200%;
      height: 100%;
      font-family: Arial, Helvetica, sans-serif;
    }
  </style>
</head>


<body>
  <div id="splash">
    loading
  </div>


  <div id="app" style="display: none">
    <nav>
      <div class="logo">{{title}}</div>
      <div id="nav-icon">☰</div>
      <input id="nav-toggle" type="checkbox">
      <div id="nav-items">
        <button v-if="account" @click="search_visible = !search_visible">Sucheinstellungen</button>
        <button v-if="account" @click="window.location.hash = ''; window.location.reload()">Logout</button>
      </div>



    </nav>


    <div class="content">


      <div v-for="auction in ordered_auctions()"
        v-if="auction.price != null && !auction.is_price_final && !search_visible">

        <div class="auction">
          <div class="thumb">
            <div class="blurredthumb" v-bind:style="{ 'background-image': 'url(' + auction.thumb+ ')' }"></div>
            <img class="thumbimg" :src="auction.thumb">
          </div>

          <div style="overflow: hidden">
            <a :href="auction.url" target="_">{{auction.desc}}</a>
            <div class="currency">€ {{auction.price}}</div>
            <div>{{ts_to_remaining(auction.timestamp)}}</div>
            <a v-bind:href="auction.gcal">Kalendereintrag</a>
            <div v-if="auction.avg_price > auction.price">
              Preistipp
            </div>
          </div>
        </div>
        <hr>
      </div>


      <div v-if="account" class="panel">
        <h3>Deine Suchen:</h3>
        <div v-for="(query, url) in queries">
          Suche <i>"{{display_query(url)}}"</i>: {{Math.round(query.avg_price)}} EUR im Schnitt
        </div>
        <button @click="search_visible = !search_visible">Sucheinstellungen</button>

        <h3>Abgelaufene Suchen:</h3>
      </div>




      <div v-for="auction in ordered_auctions()"
        v-if="auction.price != null && auction.is_price_final && !search_visible">
        <div class="auction">
          <div class="thumb">
            <div class="blurredthumb" v-bind:style="{ 'background-image': 'url(' + auction.thumb+ ')' }"></div>
            <img class="thumbimg" :src="auction.thumb">
          </div>
          <div style="overflow: hidden">
            <a :href="auction.url" target="_">{{auction.desc}}</a>
            <div class="currency">€ {{auction.price}}</div>
          </div>
        </div>
        <hr>
      </div>




      <template>
        <div class="panel" v-if="!account">
          {{account}}
          Hi! Du hast noch keinen Account oder es ist keiner geladen. Macht aber nichts, gib einfach Deinen ein oder
          denke Dir einen aus.
          <input autocapitalize="none" v-model="new_account" v-on:keyup.enter="window.location.hash = new_account;">
          <button @click="window.location.hash = new_account">OK</button>
          <div>
            Tip: der Accountname sollte einem Passwort aehnlich sein wenn Du nicht willst dass jemand anderes Deine
            Suchen sieht.
          </div>
        </div>
      </template>


      <div class="panel" v-if="search_visible">
        <div align="right">
          <button @click="search_visible = !search_visible">X</button>

        </div>
        <h1>Neue Suche</h1>
        Suchen sind das Herzstueck dieser Anwendung. Suchen laufen immer, auch wenn Du nicht online bist. Erstelle eine
        Suche die moeglichst nur das liefert was Dich interessiert. Das Ausschliessen von Sofortkauf-Artikeln, ein
        Mindestpreis sowie nur Artikel die eine WBK erfordern kann sinnvoll sein. Vergiss nicht am Ende alle zu
        speichern!
        <br>
        <br>
        <form>
          <div class="form-group">
            <label>Suchbegriff(e), durch Leerzeichen getrennt</label>
            <input autocapitalize="none" v-model="query.search">
          </div>
          <div class="form-group">
            <label>Maximalpreis</label>
            <input type="number" v-model="query.maxprice">
          </div>
          <div class="form-group">
            <label>Mindestpreis</label>
            <input type="number" v-model="query.minprice">
          </div>
          <div class="form-group">
            <input type="checkbox" v-model="query.restricted">
            <label>WBK noetig?</label>
          </div>
          <label>Auktionstyp</label>
          <div class="form-group">
            <select v-model="query.type">
              <option v-bind:value="1">Nur Auktionen</option>
              <option v-bind:value="2">Nur Sofortkauf</option>
              <option v-bind:value="3">Alles</option>
            </select>
          </div>
          <div class="form-group">
            <label>Such-URL (Kann man alternativ von eGun-Suche kopieren)</label>
            <input autocapitalize="none" v-model="query_url">
          </div>
        </form>
        <div>
          <a v-if="query_url" v-bind:href="query_url" target="_">Suche testen</a>
        </div>

        <div align="right">
          <button @click="add_query()">Suche hinzufuegen</button>
        </div>

        Bestehende Suchen:
        <div v-for="(query, url) in queries" style="font-size: 0.8em">
          <button @click="delete_query(url)">X</button> <i>
            "{{display_query(url)}}"

          </i>
        </div>

        <div align="right">

          <button @click="save_account()">Alle Suchen permanent speichern</button>
        </div>
      </div>


    </div>
  </div>
</body>
<!-- <link rel="stylesheet" href="https://rawgit.com/woelper/lilac/master/lilac.css"> -->
<link rel="stylesheet" href="https://rawgit.com/woelper/lilac/master/lilac.min.css">

<!-- Moment.js library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment-with-locales.min.js"></script>
<!-- moment-duration-format plugin -->
<script
  src="https://cdnjs.cloudflare.com/ajax/libs/moment-duration-format/1.3.0/moment-duration-format.min.js"></script>
<script defer src="https://cdn.jsdelivr.net/npm/vue@2.5.13/dist/vue.min.js"></script>
<script defer src="app.js"></script>

<style>
  :root {
    --main-color: rgb(33, 110, 81);
  }

  .nav-items {
    margin-left: auto;
    margin-right: 0;
  }

  .auction {
    margin: 10px;
    overflow: hidden;
  }

  .auction a {
    text-decoration: none;
    color: rgb(27, 162, 216);
  }

  .currency {
    font-weight: bold
  }

  .blurredthumb {
    filter: blur(8px);
    width: 100%;
    height: 100%;
    background-size: 100% 100%;
  }

  .thumb {

    width: 100px;
    height: 100px;
    float: left;
    margin-right: 30px;
    position: relative;
    background-color: #ccc;
    overflow: hidden;
  }

  .thumbimg {
    position: absolute;
    top: 0;
    bottom: 0;
    margin: auto;
  }

  #nav-icon {
    text-align: center;
    box-sizing: content-box;
  }

  @media screen and (max-width:600px) {
    #nav-items {
      width: 50%;
      box-shadow: 0px 8px 8px rgba(0, 0, 0, 0.404);

    }
  }

  hr {
    display: block;
    height: 1px;
    border: 0;
    border-top: 1px solid #ccc;
    margin: 1em 0;
    margin-left: 10px;
    margin-right: 10px;
    padding: 0;
  }
</style>