import { translate } from '../../../utils/i18n';
import { progressBarVariantOptions } from '../../../utils/constants';
import { toFloat } from '../../../utils/number_utils';
import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';

const backgroundClasses = {
  [progressBarVariantOptions.primary]: 'gl-progress-bar-primary',
  [progressBarVariantOptions.success]: 'gl-progress-bar-success',
  [progressBarVariantOptions.danger]: 'gl-progress-bar-danger',
  [progressBarVariantOptions.warning]: 'gl-progress-bar-warning'
};
var script = {
  name: 'GlProgressBar',
  props: {
    ariaLabel: {
      type: String,
      required: false,
      default: translate('GlProgressBar.ariaLabel', 'Progress bar')
    },
    value: {
      type: [Number, String],
      required: false,
      default: 0
    },
    variant: {
      type: String,
      required: false,
      default: 'primary',
      validator: value => Object.keys(progressBarVariantOptions).includes(value)
    },
    max: {
      type: [Number, String],
      required: false,
      default: 100
    },
    height: {
      type: String,
      required: false,
      default: null
    }
  },
  computed: {
    progressHeight() {
      return {
        height: this.height
      };
    },
    computedValue() {
      return toFloat(this.value, 0);
    },
    computedMax() {
      const max = toFloat(this.max, 100);
      return max > 0 ? max : 100;
    },
    progressBarStyles() {
      return {
        transform: `scaleX(${this.computedValue / this.computedMax})`
      };
    },
    classes() {
      return ['gl-progress', backgroundClasses[this.variant]];
    }
  }
};

/* 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:"gl-progress-bar progress",style:(_vm.progressHeight)},[_c('div',{class:_vm.classes,style:(_vm.progressBarStyles),attrs:{"role":"progressbar","aria-label":_vm.ariaLabel,"aria-valuemin":"0","aria-valuemax":String(_vm.computedMax),"aria-valuenow":_vm.computedValue}})])};
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 */
  
  /* style inject shadow dom */
  

  
  const __vue_component__ = __vue_normalize__(
    { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
    __vue_inject_styles__,
    __vue_script__,
    __vue_scope_id__,
    __vue_is_functional_template__,
    __vue_module_identifier__,
    false,
    undefined,
    undefined,
    undefined
  );

export default __vue_component__;
