<template>
  <div>
    <button class="delete-btn" @click="showPrompt">
      🚮
    </button>
    <div v-if="openPrompt" :class="{ open: openPrompt }" class="prompt">
      <h3>You will delete '{{ item.name }}'?</h3>
      <div class="actions">
        <button class="btn btn--cancel" @click="openPrompt = false">No</button>
        <button class="btn btn--success" @click="removeFruit(item.id)">Yes</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "DeleteItem",
  props: {
    item: Object,
    redirect: {
      type: Function,
      default: () => {}
    }
  },
  data() {
    return {
      openPrompt: false
    };
  },
  methods: {
    showPrompt() {
      this.openPrompt = true;
    },
    removeFruit(id) {
      this.$store.dispatch("removeFruit", id).then(() => this.redirect());
    }
  }
};
</script>

<style scoped lang="less">
.prompt {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 2;
  background: rgb(230, 107, 107);
  background: linear-gradient(90deg, rgba(230, 107, 107, 1) 0%, rgba(214, 48, 49, 1) 100%);
  width: 0;
  height: 0;
  transition: all 0.4s ease-in-out;
  color: @color-2;
  display: flex;
  flex-flow: column;
  align-items: center;
  justify-content: center;

  &.open {
    width: 100%;
    height: 100%;
  }

  .btn {
    border: none;
    border-radius: 4px;
    color: @color-2;
    padding: 0.5rem 1.35rem;
    margin: 0 0.5rem;

    &--success {
      background-color: #2ecc71;
    }

    &--cancel {
      background-color: darken(#cecece, 15%);
    }
  }
}

.delete-btn {
  position: absolute;
  z-index: 1;
  top: 0;
  right: 0;
  width: 55px;
  padding: 0.75rem 0.75rem 1.35rem 1.35rem;
  background: rgb(230, 107, 107);
  background: linear-gradient(180deg, rgba(230, 107, 107, 0.6) 0%, rgba(214, 48, 49, 1) 100%);
  border: none;
  border-bottom-left-radius: 100%;
}
</style>
