'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var __chunk_5 = require('./chunk-13e039f5.js');

//
//
//
//
//
//
//
//
//
//
//
//
//
var script = {
  name: 'BProgress',
  props: {
    type: {
      type: [String, Object],
      default: 'is-darkgrey'
    },
    size: String,
    value: {
      type: Number,
      default: undefined
    },
    max: {
      type: Number,
      default: 100
    },
    showValue: {
      type: Boolean,
      default: false
    },
    format: {
      type: String,
      default: 'raw',
      validator: function validator(value) {
        return ['raw', 'percent'].indexOf(value) >= 0;
      }
    },
    precision: {
      type: Number,
      default: 2
    },
    keepTrailingZeroes: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    isIndeterminate: function isIndeterminate() {
      return this.value === undefined || this.value === null;
    },
    newType: function newType() {
      return [this.size, this.type];
    },
    newValue: function newValue() {
      if (this.value === undefined || this.value === null || isNaN(this.value)) {
        return undefined;
      }

      if (this.format === 'percent') {
        var _val = this.toFixed(this.value * 100 / this.max);

        return "".concat(_val, "%");
      }

      var val = this.toFixed(this.value);
      return val;
    }
  },
  watch: {
    value: function value(_value) {
      this.setValue(_value);
    }
  },
  methods: {
    /**
    * When value is changed back to undefined, value of native progress get reset to 0.
    * Need to add and remove the value attribute to have the indeterminate or not.
    */
    setValue: function setValue(value) {
      if (this.isIndeterminate) {
        this.$refs.progress.removeAttribute('value');
      } else {
        this.$refs.progress.setAttribute('value', value);
      }
    },
    // Custom function that imitate the javascript toFixed method with improved rounding
    toFixed: function toFixed(num) {
      var fixed = (+"".concat(Math.round(+"".concat(num, "e").concat(this.precision)), "e").concat(-this.precision)).toFixed(this.precision);

      if (!this.keepTrailingZeroes) {
        fixed = fixed.replace(/\.?0+$/, '');
      }

      return fixed;
    }
  },
  mounted: function mounted() {
    this.setValue(this.value);
  }
};

/* script */
const __vue_script__ = script;

/* template */
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"progress-wrapper"},[_c('progress',{ref:"progress",staticClass:"progress",class:_vm.newType,attrs:{"max":_vm.max}},[_vm._v(_vm._s(_vm.newValue))]),_vm._v(" "),(_vm.showValue)?_c('p',{staticClass:"progress-value"},[_vm._t("default",[_vm._v(_vm._s(_vm.newValue))])],2):_vm._e()])};
var __vue_staticRenderFns__ = [];

  /* style */
  const __vue_inject_styles__ = undefined;
  /* scoped */
  const __vue_scope_id__ = undefined;
  /* module identifier */
  const __vue_module_identifier__ = undefined;
  /* functional template */
  const __vue_is_functional_template__ = false;
  /* style inject */
  
  /* style inject SSR */
  

  
  var Progress = __chunk_5.__vue_normalize__(
    { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
    __vue_inject_styles__,
    __vue_script__,
    __vue_scope_id__,
    __vue_is_functional_template__,
    __vue_module_identifier__,
    undefined,
    undefined
  );

var Plugin = {
  install: function install(Vue) {
    __chunk_5.registerComponent(Vue, Progress);
  }
};
__chunk_5.use(Plugin);

exports.BProgress = Progress;
exports.default = Plugin;
