<template>
  <div
    class="m-progress-bar text-center"
    :style="{'--backgroundColor': backgroundColor, '--borderColor': fillColor, '--height': height}">
    <!-- @slot Put content before the progress bar -->
    <slot
      name="before"
      :percentage="percentage" />
    <div
      class="wrapper-progress">
      <div class="progress">
        <div
          :aria-valuenow="percentage"
          :style="{width: percentage + '%'}"
          :class="{'mr-1': percentage < 10}"
          class="progress-bar"
          role="progressbar"
          aria-valuemin="0"
          aria-valuemax="100">
          <slot
            v-if="percentage >= 10"
            name="inside"
            :percentage="percentage" />
          <span class="sr-only">{{ percentage }} Complete</span>
        </div>
        <!-- @slot Put content inside the progress bar -->
        <slot
          v-if="percentage < 10"
          name="inside"
          :percentage="percentage" />
      </div>
    </div>
    <!-- @slot Put content after the progress bar -->
    <slot
      name="after"
      :percentage="percentage" />
  </div>
</template>

<script>
/**
 * A progressbar with controls by props. Text as descriptions can be added at top, center or bottom with slot templates.
 */
export default {
  name: 'MProgressBar',
  props: {
    /**
     * Whether to disable button
     */
    backgroundColor: {
      type: String,
      default: 'rgba(255, 255, 255, .4)',
    },
    fillColor: {
      type: String,
      default: '#c1cbcf',
    },
    height: {
      type: String,
      default: '10px',
    },
    percentage: {
      type: Number,
      default: 0,
    },
  },
  computed: {
    barClass() {
      if (this.percentage >= 75) {
        return 'danger';
      }
      if (this.percentage >= 50) {
        return 'warning';
      }
      return '';
    },
  },
};
</script>

<style lang="scss" scoped>
.m-progress-bar .wrapper-progress {
  position: relative;

  padding: 2px;

  background: var(--backgroundColor);

  border: 1px solid var(--borderColor);
  border-radius: 20px;
}

.m-progress-bar .progress {
  height: var(--height);

  background: none;

  border-radius: 20px;
}

.m-progress-bar .progress-bar {
  position: relative;

  background: var(--borderColor);

  border-radius: 40px;
  box-shadow: none;
}

</style>
