import { IMovie } from "@autoplex-api/request";
import { Mutation } from "../../store";
import { defineComponent } from "vue";

export default defineComponent({
	computed: {
		storedMovies(): IMovie[] {
			return this.$store.getters.movies(this.movies);
		}
	},
	unmounted() {
		if (this.movies.length > 0) {
			this.$store.commit(Mutation.FreeMovies, this.movies);
		}
	},
	props: {
		movies: {
			default: <IMovie[]>[]
		}
	},
	watch: {
		movies(newValue, oldValue) {
			if (newValue.length > 0) {
				this.$store.commit(Mutation.StoreMovies, newValue);
			}
			if (oldValue.length > 0) {
				this.$store.commit(Mutation.FreeMovies, oldValue);
			}
		}
	}
})
