<template>
  <div class="annotated-media-view">
    <div class="media">
      <annotated-image :data="currentMedia" :project="currentProject" :socket="socket"/>
    </div>

    <div class="control">
      <media-control :hasPrevious="hasPrevious" :hasNext="hasNext"
                     @previous="previous" @next="next"/>
    </div>

    <div class="selector">
      <media-selector :project="currentProject"
                      :current="currentMedia"
                      :socket="socket"
                      @click="current = $event"/>
    </div>
  </div>
</template>

<script>
import MediaSelector from "@/components/media/media-selector";
import AnnotatedImage from "@/components/media/annotated-image";
import MediaControl from "@/components/media/media-control";

export default {
  name: "annotated-media-view",
  components: {MediaControl, AnnotatedImage, MediaSelector},
  props: ['currentProject', 'socket'],
  data: function() {
    return {
      current: 0
    };
  },
  computed: {
    hasPrevious: function() {
      return this.current > 0;
    },
    hasNext: function() {
      return this.current < this.currentProject.data.length - 1;
    },
    currentMedia: function() {
      if (this.current < this.currentProject.data.length)
        return this.currentProject.data[this.current];
      else
        return false;
    }
  },
  methods: {
    previous: function() {
      if (this.hasPrevious)
        this.current -= 1;
    },
    next: function() {
      if (this.hasNext)
        this.current += 1;
    }
  }
}
</script>

<style scoped>
.annotated-media-view {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.3);
}

.media {
  flex-grow: 1;
  position: relative;
}

.annotated-image {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;

  display: flex;
  align-items: center;
  justify-content: center;
}

.control {
  background-color: rgba(0, 0, 0, 0.8);
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

.selector {
  overflow-x: auto;
  white-space: nowrap;
  background-color: rgba(0, 0, 0, 0.5);
}
</style>