<template>
  <div>
    <h2><span @click="() => this.$router.push('/')">◀</span> Details</h2>

    <article>
      <img :src="fruit.image" :alt="fruit.name" />
      <section>
        <h3>
          {{ fruit.name }}
          <span class="tag" :style="{ backgroundColor: fruit.color }">{{ fruit.taste }}</span>
        </h3>

        <p>{{ fruit.description }}</p>

        <hr />

        <p class="price">${{ fruit.price | noDecimal }}</p>
        <div class="alert">
          {{ "This offer " + expirationState }} {{ fruit.expires | moment("from", "now") }}
        </div>
      </section>
    </article>
  </div>
</template>

<script>
import { mapState } from "vuex";

export default {
  name: "FruitDetails",
  data() {
    return {
      modalOpen: true
    };
  },
  filters: {
    noDecimal(value) {
      return parseInt(value).toFixed();
    }
  },
  computed: {
    ...mapState(["fruit"]),
    expirationState() {
      return new Date(this.fruit.expires) < new Date() ? "expired" : "expires";
    }
  }
};
</script>

<style lang="less" scoped>
h2 span {
  cursor: pointer;
}
article {
  display: flex;
  align-items: center;
  flex-flow: column;

  img,
  section {
    border-radius: 10px;
  }

  img {
    width: 100%;
    object-fit: scale-down;
    margin-bottom: 1.5rem;
    box-shadow: 0 1px 4px 1px #d2d2f2;
  }

  section {
    padding: 1.5rem 2rem;
    background-color: @color-2;

    h3 {
      display: flex;
      align-items: center;
      justify-content: flex-start;
      margin-bottom: 0.55rem;
      font-size: 34px;
    }

    hr {
      width: 100px;
      color: #cece;
      margin: 1.35rem auto;
    }

    .tag {
      border-radius: 25px;
      padding: 0.35rem 0.75rem;
      margin-left: 0.75rem;
      color: #ffffff;
      font-size: 14px;
      font-weight: bold;
      text-align: center;
      text-transform: lowercase;
    }

    .price {
      text-align: center;
      margin: 0;
      font-size: 28px;
      font-weight: bold;
      color: @color-3;
    }
  }

  @media screen and (min-width: @sm) {
    flex-flow: row;
    align-items: flex-start;
    justify-content: center;

    img,
    section {
      width: 50%;
      max-width: 485px;
    }

    img {
      max-height: 435px;
      margin-bottom: 0;
      margin-right: 1.5rem;
      object-fit: cover;
    }
  }
}

.alert {
  margin-top: 1.75rem;
  background: linear-gradient(112.4deg, #1c9797 11.05%, #147171 89.93%);
  color: @color-2;
  padding: 1rem 1.5rem;
  border-radius: 4px;
}
</style>
