<template>
  <div :class="{ 'is-shown': show, 'is-contained': contained }" class="cover">
    <ul class="loader">
      <li />
      <li />
      <li />
      <li />
      <li />
      <li />
    </ul>
  </div>
</template>

<script>
export default {
  props: {
    show: {
      type: Boolean,
      required: false,
      default: false
    },
    contained: {
      type: Boolean,
      required: false,
      default: false
    }
  }
}
</script>

<style lang="scss" scoped>
.cover {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  z-index: 100000;
  background-color: rgba(255, 255, 255, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: all 350ms ease;

  &.is-contained {
    position: absolute;
  }

  .loader li {
    background: #535353;
    margin-left: 1px;
    width: 14px;
    height: 22px;
    display: inline-block;
    opacity: 0;
    border-radius: 2px;
    box-shadow: 0px 0px 1px #b4b4b4;
    transform: skew(-25deg, 0deg) scale(0.1);
    animation: loader 0.5s ease-in-out infinite alternate;
  }

  @keyframes loader {
    to {
      transform: skew(-25deg, 0deg) scale(1);
      opacity: 1;
    }
  }

  .loader li:nth-child(2) {
    animation-delay: 0.1s;
  }
  .loader li:nth-child(3) {
    animation-delay: 0.2s;
  }
  .loader li:nth-child(4) {
    animation-delay: 0.3s;
  }
  .loader li:nth-child(5) {
    animation-delay: 0.4s;
  }
  .loader li:nth-child(6) {
    animation-delay: 0.5s;
  }

  &.is-shown {
    pointer-events: all;
    opacity: 1;

    .spinner {
      transform: scale(1);
    }
  }
}
</style>
