<template>
  <div class="modal">
    <h2>New Fruit</h2>
    <form id="new-fruit">
      <!-- name -->
      <p>
        <input ref="autofocus" type="text" v-model="fruit.name" placeholder="Name" />
      </p>

      <!-- image finder (with Unsplash API) -->
      <ImageUnsplash
        @getValue="getImage"
        label="Image"
        placeholder="Search: strawberry, apple ..."
      />

      <div class="input-group">
        <!-- taste -->
        <input type="text" v-model="fruit.taste" placeholder="Taste" />

        <!-- color -->
        <input type="color" v-model="fruit.color" placeholder="Color" />
      </div>

      <!-- price -->
      <p>
        <input type="number" v-model="fruit.price" placeholder="Price" />
      </p>

      <!-- expires -->
      <p>
        <input type="date" v-model="fruit.expires" placeholder="Expiry date" />
      </p>

      <!-- description -->
      <p>
        <textarea v-model="fruit.description" placeholder="Message ..." />
      </p>
    </form>
  </div>
</template>

<script>
import ImageUnsplash from "./Form/ImageUnsplash/ImageUnsplash";

export default {
  name: "AddFruit",
  components: { ImageUnsplash },
  data() {
    return {
      fruit: {}
    };
  },
  mounted() {
    this.$refs["autofocus"].focus();
  },
  methods: {
    getImage(url) {
      this.fruit.image = url;
    }
  }
};
</script>

<style lang="less">
.modal {
  position: absolute;
  top: @headerHeight;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100%;
  background-color: @color-2;
  padding: 1rem;
  z-index: 14;

  form {
    border: 2px solid @color-1;
    border-radius: 10px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='88' height='88' viewBox='0 0 88 88'%3E%3Cg fill='%230c9696' fill-opacity='0.35'%3E%3Cpath fill-rule='evenodd' d='M29.42 29.41c.36-.36.58-.85.58-1.4V0h-4v26H0v4h28c.55 0 1.05-.22 1.41-.58h.01zm0 29.18c.36.36.58.86.58 1.4V88h-4V62H0v-4h28c.56 0 1.05.22 1.41.58zm29.16 0c-.36.36-.58.85-.58 1.4V88h4V62h26v-4H60c-.55 0-1.05.22-1.41.58h-.01zM62 26V0h-4v28c0 .55.22 1.05.58 1.41.37.37.86.59 1.41.59H88v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6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-4a2 2 0 1 0 0-4 2 2 0 0 0 0 4zm0-68A6 6 0 1 1 8 2a6 6 0 0 1 0 12zm0-4a2 2 0 1 0 0-4 2 2 0 0 0 0 4zm36 36a2 2 0 1 0 0-4 2 2 0 0 0 0 4z'/%3E%3C/g%3E%3C/svg%3E");
    background-attachment: scroll;
    background-color: rgba(0, 0, 0, 0.06);
    box-shadow: 0 1px 4px 1px #d2d2f2;
    padding: 1rem;

    .input-group {
      display: flex;
      align-items: center;
      margin: 1rem 0;

      [type="color"] {
        width: 35%;
        height: 48px;
      }

      :first-child {
        margin-right: 1rem;
      }
    }

    input,
    .image-unsplash {
      box-sizing: border-box;
      width: 100%;
      border-radius: 4px;
      border: 1px solid #cecece;
      background-color: @color-2;
      padding: 0.75rem 1rem;
    }
  }
}
</style>
