<template>
  <transition name="co-indicator">
    <div class="co-indicator" v-show="visible">
      <div class="co-indicator-wrapper" :class="className" :style="{ 'padding': text ? '19px 22px' : '13px 15px' }">
        <spinner class="co-indicator-spin" :type="convertedSpinnerType" :size="30"></spinner>
        <span class="co-indicator-text" v-show="text">{{ text }}</span>
      </div>
      <div class="co-indicator-mask" @touchmove.stop.prevent></div>
    </div>
  </transition>
</template>

<style>
@component-namespace co {
  @component indicator {
    transition: opacity .2s linear;

    @descendent wrapper {
      position: fixed 50% * * 50%;
      transform: translate(-50%, -50%);
      border-radius: 8px;
      background: rgba(0, 0, 0, 0.7);
      color: white;
      box-sizing: border-box;
      text-align: center;
    }

    @descendent text {
      display: block;
      color: #fff;
      text-align: center;
      margin-top: 0.4rem;
      font-size: 0.75rem;
    }

    @descendent spin {
      display: inline-block;
      text-align: center;
    }

    @descendent mask {
      position: fixed 0 * * 0;
      size: 100%;
      opacity: 0;
      background: transparent;
    }
  }
}

.co-indicator-enter,
.co-indicator-leave-active {
  opacity: 0;
}
</style>

<script type="text/babel">
  import Spinner from 'CoUI/packages/spinner/index.js';
  if (process.env.NODE_ENV === 'component') {
    require('CoUI/packages/spinner/style.css');
  }

  export default {
    data() {
      return {
        visible: false
      };
    },

    components: {
      Spinner
    },

    computed: {
      convertedSpinnerType() {
        switch (this.spinnerType) {
          case 'double-bounce':
            return 1;
          case 'triple-bounce':
            return 2;
          case 'fading-circle':
            return 3;
          default:
            return 0;
        }
      }
    },

    props: {
      className: String,
      text: String,
      spinnerType: {
        type: String,
        default: 'snake'
      }
    }
  };
</script>
