<template>
  <div class="publish-buttons">
    <button class="btn btn-success" @click="publish" :disabled="!canPublish || awaitingChange" v-if="!isPublished">
      <span class="icon-rocket"></span> Live zetten
    </button>

    <button class="btn btn-warning" @click="depublish" :disabled="!canPublish || awaitingChange" v-else>
      <span class="icon-switch"></span> Depubliceren
    </button>
  </div>
</template>

<script lang="ts">
import { Component, Emit, Prop, Vue, Watch } from 'vue-property-decorator';

@Component({})
export default class PublishButtons extends Vue {
  @Prop({ required: true, type: Boolean }) readonly isPublished!: boolean;
  @Prop({ required: true, type: Boolean }) readonly canPublish!: boolean;
  @Prop({ required: true, type: String }) readonly itemId!: string;

  awaitingChange = false;

  @Emit('publish')
  publish() {
    this.awaitingChange = true;
  }

  @Emit('depublish')
  depublish() {
    this.awaitingChange = true;
  }

  @Watch('isPublished')
  onIsPublishedChanged() {
    this.awaitingChange = false;
  }
}
</script>
