<template>
  <section
    id="Content"
    class="p-6 pb-24 min-h-screen flex flex-col justify-center"
  >
    <!-- Breadcrumb -->
    <div>
      <!-- Back -->
      <div class="text-lg text-center font-light relative px-7">
        <h1
          class="text-lg text-center px-2 py-1 absolute -left-2 -top-1"
          @click="$router.back()"
        >
          <fa icon="chevron-left" class="fa-fw"></fa>
        </h1>
      </div>

      <!-- Heading -->
      <h1 id="ViewHeading" class="text-4xl text-center font-light pt-4 mb-8">
        Start Here
      </h1>
    </div>

    <!-- id used by puppeteer test script -->
    <div id="start-question" class="mt-8">
      <div class="max-w-3xl mx-auto">
        <p class="text-center text-xl font-light">
          Do you want a new identifier of your own?
        </p>
        <p class="text-center font-light">
          If you haven't used this before, click "Yes" to generate a new
          identifier.
        </p>
        <p class="text-center mb-4 font-light">
          Only click "No" if you have a seed of 12 or 24 words generated
          elsewhere.
        </p>
        <a
          @click="onClickYes()"
          class="block w-full text-center text-lg uppercase bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-3 rounded-md mb-2"
        >
          Yes, generate one
        </a>
        <div class="grid grid-cols-1 sm:grid-cols-2 gap-2">
          <a
            @click="onClickNo()"
            class="block w-full text-center text-md uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-2 rounded-md"
          >
            No, I have a seed
          </a>
          <a
            v-if="numAccounts > 0"
            @click="onClickDerive()"
            class="block w-full text-center text-md uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-2 rounded-md"
          >
            Derive new address from existing seed
          </a>
        </div>
      </div>
    </div>
  </section>
</template>

<script lang="ts">
import { Component, Vue } from "vue-facing-decorator";
import { accountsDB } from "@/db/index";

@Component({
  components: {},
})
export default class StartView extends Vue {
  numAccounts = 0;

  async mounted() {
    await accountsDB.open();
    this.numAccounts = await accountsDB.accounts.count();
  }

  public onClickYes() {
    this.$router.push({ name: "new-identifier" });
  }

  public onClickNo() {
    this.$router.push({ name: "import-account" });
  }

  public onClickDerive() {
    this.$router.push({ name: "import-derive" });
  }
}
</script>