<template>
  <div class="label-provider-settings">
    <button-input type="primary"
                  :disabled="labelProviderQueued"
                  @click="executeLabelProvider">
      evaluate
      <loading-icon v-if="labelProviderQueued"/>
    </button-input>
  </div>
</template>

<script>
import ButtonInput from "@/components/base/button-input";
import LoadingIcon from "@/components/base/loading-icon";

export default {
  name: "label-provider-settings",
  components: {LoadingIcon, ButtonInput},
  props: ['jobs'],
  computed: {
    labelProviderQueued: function () {
      return this.jobs
          .filter(j => !j.finished && j.type === 'Label Provider')
          .length > 0;
    }
  },
  methods: {
    executeLabelProvider: function () {
      // TODO then / error
      this.$root.socket.post(`/projects/${this.$root.project.identifier}/label_provider`, {'execute': true});
    }
  }
}
</script>

<style scoped>
.loading-icon {
  float: right;
  width: 1.3rem;
  height: 1.3rem;
  margin: -0.15rem -0.4rem -0.15rem 0.5rem;
}
</style>