<template>
  <section>
    <div class="content">
      <p class="title is-5">Steuerung</p>
      <ul>
        <li>Linksklick: Türchen hochzählen</li>
        <li>Rechtsklick: Türchen runterzählen</li>
      </ul>
    </div>
    <figure class="image">
      <img src="@/assets/adventskalender.jpg" />
      <ThouCanvas>
        <template v-for="(door, index) in doors" :key="`door-${index}`">
          <SVGRectText
            v-if="door.day >= 0"
            :text="String(door.day)"
            :rectangle="door.position"
          />
          <SVGRect
            :rectangle="door.position"
            :focused="door.day >= 0"
            @click.left="door.day++"
            @click.right="door.day--"
            style="cursor: pointer"
          />
        </template>
      </ThouCanvas>
    </figure>
  </section>
</template>

<script lang="ts">
import { Options, Vue } from "vue-class-component";
import { Door } from "./calendar";

import ThouCanvas from "../rects/ThouCanvas.vue";
import SVGRect from "../rects/SVGRect.vue";
import SVGRectText from "../rects/SVGRectText.vue";

@Options({
  components: {
    ThouCanvas,
    SVGRect,
    SVGRectText,
  },
  props: {
    doors: Array,
  },
  emits: ["update:doors"],
})
export default class extends Vue {
  private doors!: Door[];

  public beforeUnmount() {
    this.$emit("update:doors", this.doors);
  }
}
</script>

<style lang="scss" scoped>
section > figure {
  user-select: none;
}
</style>