<template>
  <div ref="rain_floor" class="rain_floor">
    <hr v-for="index in counter"
        :key="index"
        :ref="`_f${index}`"
        :style="rs(index)"
        :class="isthunder(index)"
    />
  </div>
</template>
<script>
export default {
  name: "BgRainMatrix",
  props: {
    // eslint-disable-next-line vue/require-default-prop
    title: String,
    // eslint-disable-next-line vue/require-default-prop
    bolded: String,
    counter: {
      type: Number,
      default: 100
    }
  },
  mounted() {
    const _this = this
    this.$nextTick(() => {
      if (window !== undefined) {
        // console.log(_this.$refs)
      }
    })
  },
  methods: {
    isthunder(i) {
      if (i === this.counter - 1) {
        return "thunder"
      } else {
        return ""
      }
    },
    rs(i) {
      if (i === this.counter - 1) {
        return {}
      } else {
        return {
          left: Math.floor(Math.random() * window.innerWidth) + "px",
          animationDuration: 0.2 + Math.random() * 0.3 + "s",
          animationDelay: Math.random() * 5 + "s"
        }
      }
    }
  }
}
</script>

<style lang="scss">
* {
  margin: 0;
  padding: 0;
}

:root {
  --thunder-duration: 10s;
  --thunder-delay: 5s;
}

.rain_floor {
  background-image: linear-gradient(to bottom, #030420, #000000 70%);
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
  overflow: hidden;

  hr.thunder {
    border: unset;
    position: absolute;
    width: 100vw;
    height: 100vh;
    animation-name: thunder;
    animation-duration: var(--thunder-duration);
    animation-timing-function: linear;
    animation-delay: var(--thunder-delay);
    animation-iteration-count: infinite;
  }

  hr:not(.thunder) {
    width: 50px;
    border-color: transparent;
    border-right-color: rgba(255, 255, 255, 0.7);
    border-right-width: 50px;
    position: absolute;
    bottom: 100%;
    transform-origin: 100% 50%;
    animation-name: rain;
    animation-duration: 1s;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
  }

  @keyframes rain {
    from {
      transform: rotate(105deg) translateX(0);
    }
    to {
      transform: rotate(105deg) translateX(calc(100vh + 20px));
    }
  }

  @keyframes thunder {
    0% {
      background-color: transparent;
    }
    1% {
      background-color: white;
    }
    2% {
      background-color: rgba(255, 255, 255, 0.8);
    }
    8% {
      background-color: transparent;
    }
  }
}

</style>
