<template>
    <div>
        <b-card :title="`Season ${this.$route.params.season} Episode ${this.$route.params.episode} \
        - ${episode != null ? episode.title : ''}`" class="mb-4">
            <span v-if="episode">
                {{ episode.description }}
            </span>
            <CharacterList v-if="episode.characters" :characters="episode.characters"></CharacterList>
        </b-card>
        <div v-if="episode != null">
            <b-card v-for="(scene, scene_index) in episode.scenes" :key="`scene-${scene_index}`" :id="scene_index"
                    class="mb-1" body-class="p-0 py-2">
                <b-card-text>
                    <QuoteList :quotes="scene.quotes"></QuoteList>
                </b-card-text>
            </b-card>
        </div>
    </div>
</template>

<style>
    .card-title { font-family: 'Montserrat', sans-serif; font-weight: 600; }
</style>

<script>
import axios from 'axios';
import QuoteList from './QuoteList.vue';
import CharacterList from './CharacterList.vue';

export default {
  name: 'Episode',
  components: {
    QuoteList,
    CharacterList,
  },
  data() {
    return {
      episode: null,
    };
  },
  methods: {
    getEpisode() {
      const path = `http://localhost:5000/api/episode/${this.$route.params.season}/${this.$route.params.episode}/`;
      axios.get(path)
        .then((res) => {
          this.episode = res.data;
        })
        .catch((error) => {
          // eslint-disable-next-line no-console
          console.error(error);
        });
    },
  },
  created() {
    this.getEpisode();
  },
  watch: {
    $route() {
      this.getEpisode();
      console.log(this.$route.params.hash);
      this.$scrollTo(`${this.$route.hash}`, 500, { easing: 'ease-in-out' });
    },
  },
};
</script>
