<template>
  <div class="ipub-progress">
    <div class="ipub-p2 ipub-progress-title">
      {{title}}
    </div>
    <div :class="['ipub-progress-content', 'ipub-progress-content--'+type]"
         :style="{width: progress+'%'}">
      <div class="ipub-p2 ipub-progress-content-title">
        {{title || ('Importing' + (type==='SUCCESS'?' Successfully':type==="FAILURE"?' Failure':'') + ' ' + progress + '%')}}
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'IpubProgress',
  props: {
    progress: {
      type: Number,
      default: 0
    },
    type: {
      type: String,
      default: 'PROCESSING',
      validator (val) {
        return ['PROCESSING', 'SUCCESS', 'FAILURE'].indexOf(val) !== -1
      }
    },
    title: {
      type: String,
      default: ''
    }
  },
  methods: {
    handleClick (e) {
      this.$emit('click', e)
    }
  }
}
</script>

<style lang="scss" scoped>
.ipub-progress {
  background: $body_color;
  border: 1px solid $border_color;
  height: 40px;
  box-sizing: border-box;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
  &-title {
    position: absolute;
    line-height: 38px;
    padding-left: 20px;
  }
  &-content {
    position: absolute;
    height: 100%;
    background: $main_color;
    border-radius: 4px;
    overflow: hidden;
    transition: 0.3s all;
    &--SUCCESS {
      background: $success_color;
    }
    &--FAILURE {
      background: $key_color;
    }
    &-title {
      color: #fff;
      line-height: 38px;
      padding-left: 20px;
    }
  }
}
</style>
