'use strict';Object.defineProperty(exports,'__esModule',{value:true});var normalizeComponent=require('./normalize-component-d9981c57.js');require('./es.array.includes-3990bfec.js'),require('./es.number.constructor-daccdeab.js'),require('./es.object.to-string-f27a75a8.js'),require('./es.array.concat-bb8715dc.js');var _export=require('./export-61511812.js');require('./es.string.includes-ec03e639.js');var BaseButton=require('./BaseButton-0200f360.js'),BaseIcon=require('./BaseIcon-1ed3bf6e.js'),BaseLoader=require('./BaseLoader-a331376d.js'),BasePopUp=require('./BasePopUp-e1cc1880.js'),BaseProgressBar=require('./BaseProgressBar-a9d3b0ce.js'),i18n=require('./i18n-68e039d3.js');require('./object-keys-12f2c5e5.js'),require('./object-set-prototype-of-dfa14cf5.js'),require('./classof-819fc780.js'),require('./array-species-create-c414c2ec.js'),require('./create-property-240c71a5.js'),require('./array-method-has-species-support-983ac207.js'),require('./is-regexp-d6f1551e.js'),require('./es.symbol.description-bf683260.js'),require('./set-to-string-tag-240bb3b0.js'),require('./array-iteration-f8b4483d.js'),require('./function-bind-context-e4685306.js'),require('./utils-2e136d65.js'),require('./typeof-6b9e62b8.js'),require('./unsupportedIterableToArray-40a00645.js'),require('./es.array.join-88750c41.js'),require('./array-method-is-strict-99341ee3.js'),require('./es.array.map-4cfed4ef.js'),require('./regexp-exec-abstract-216cd44a.js'),require('./string-multibyte-a2dff6e3.js'),require('./regexp-flags-abc49c4a.js'),require('./es.string.split-98e29ede.js'),require('./es.regexp.to-string-5606f728.js'),require('./es.string.replace-25e9e098.js'),require('./es.array.sort-7d68b195.js'),require('./web.dom-collections.for-each-c07b0e22.js'),require('./dom-iterables-e2602b7e.js'),require('./es.object.keys-c57f02bd.js'),require('./BaseBoxTooltip-59ec05c0.js'),require('./popUpLock-85f8cf1c.js');// `thisNumberValue` abstract operation
// https://tc39.es/ecma262/#sec-thisnumbervalue
var thisNumberValue = function (value) {
  if (typeof value != 'number' && _export.c(value) != 'Number') {
    throw TypeError('Incorrect invocation');
  }
  return +value;
};// `String.prototype.repeat` method implementation
// https://tc39.es/ecma262/#sec-string.prototype.repeat
var stringRepeat = function repeat(count) {
  var str = String(_export.a(this));
  var result = '';
  var n = _export.t(count);
  if (n < 0 || n == Infinity) throw RangeError('Wrong number of repetitions');
  for (;n > 0; (n >>>= 1) && (str += str)) if (n & 1) result += str;
  return result;
};var nativeToFixed = 1.0.toFixed;
var floor = Math.floor;

var pow = function (x, n, acc) {
  return n === 0 ? acc : n % 2 === 1 ? pow(x, n - 1, acc * x) : pow(x * x, n / 2, acc);
};

var log = function (x) {
  var n = 0;
  var x2 = x;
  while (x2 >= 4096) {
    n += 12;
    x2 /= 4096;
  }
  while (x2 >= 2) {
    n += 1;
    x2 /= 2;
  } return n;
};

var multiply = function (data, n, c) {
  var index = -1;
  var c2 = c;
  while (++index < 6) {
    c2 += n * data[index];
    data[index] = c2 % 1e7;
    c2 = floor(c2 / 1e7);
  }
};

var divide = function (data, n) {
  var index = 6;
  var c = 0;
  while (--index >= 0) {
    c += data[index];
    data[index] = floor(c / n);
    c = (c % n) * 1e7;
  }
};

var dataToString = function (data) {
  var index = 6;
  var s = '';
  while (--index >= 0) {
    if (s !== '' || index === 0 || data[index] !== 0) {
      var t = String(data[index]);
      s = s === '' ? t : s + stringRepeat.call('0', 7 - t.length) + t;
    }
  } return s;
};

var FORCED = nativeToFixed && (
  0.00008.toFixed(3) !== '0.000' ||
  0.9.toFixed(0) !== '1' ||
  1.255.toFixed(2) !== '1.25' ||
  1000000000000000128.0.toFixed(0) !== '1000000000000000128'
) || !normalizeComponent.f(function () {
  // V8 ~ Android 4.3-
  nativeToFixed.call({});
});

// `Number.prototype.toFixed` method
// https://tc39.es/ecma262/#sec-number.prototype.tofixed
_export._({ target: 'Number', proto: true, forced: FORCED }, {
  toFixed: function toFixed(fractionDigits) {
    var number = thisNumberValue(this);
    var fractDigits = _export.t(fractionDigits);
    var data = [0, 0, 0, 0, 0, 0];
    var sign = '';
    var result = '0';
    var e, z, j, k;

    if (fractDigits < 0 || fractDigits > 20) throw RangeError('Incorrect fraction digits');
    // eslint-disable-next-line no-self-compare -- NaN check
    if (number != number) return 'NaN';
    if (number <= -1e21 || number >= 1e21) return String(number);
    if (number < 0) {
      sign = '-';
      number = -number;
    }
    if (number > 1e-21) {
      e = log(number * pow(2, 69, 1)) - 69;
      z = e < 0 ? number * pow(2, -e, 1) : number / pow(2, e, 1);
      z *= 0x10000000000000;
      e = 52 - e;
      if (e > 0) {
        multiply(data, 0, z);
        j = fractDigits;
        while (j >= 7) {
          multiply(data, 1e7, 0);
          j -= 7;
        }
        multiply(data, pow(10, j, 1), 0);
        j = e - 1;
        while (j >= 23) {
          divide(data, 1 << 23);
          j -= 23;
        }
        divide(data, 1 << j);
        multiply(data, 1, 1);
        divide(data, 2);
        result = dataToString(data);
      } else {
        multiply(data, 0, z);
        multiply(data, 1 << -e, 0);
        result = dataToString(data) + stringRepeat.call('0', fractDigits);
      }
    }
    if (fractDigits > 0) {
      k = result.length;
      result = sign + (k <= fractDigits
        ? '0.' + stringRepeat.call('0', fractDigits - k) + result
        : result.slice(0, k - fractDigits) + '.' + result.slice(k - fractDigits));
    } else {
      result = sign + result;
    } return result;
  }
});var script = {
  name: 'BaseUploadPopUp',
  components: {
    BaseButton: BaseButton["default"],
    BaseIcon: BaseIcon["default"],
    BaseLoader: BaseLoader["default"],
    BasePopUp: BasePopUp.B,
    BaseProgressBar: BaseProgressBar.B
  },
  mixins: [i18n.i],
  props: {
    /**
     * register files to upload<br>
     * array with file-object(s) from file-input field
     */
    fileList: {
      type: Array,
      default: function _default() {
        return [];
      }
    },

    /**
     * define current status<br>
     * possible values: 'initial' | 'saving' | 'success' | 'failed'
     */
    currentStatus: {
      type: String,
      default: 'initial',
      validate: function validate(val) {
        return ['initial', 'saving', 'success', 'failed'].includes(val);
      }
    },

    /**
     * define button text<br>
     * could be string or path to i18n json as well
     */
    cancelButtonText: {
      type: String,
      default: 'cancel'
    },

    /**
     * specify informational texts for the component -
     * this needs to be an object with the following properties<br>
     * <br>
     *   <b>title</b>: text used in the popup header<br>
     *   <b>upload</b>: default button text<br>
     *   <b>done</b>: button text when upload finished<br>
     *   <b>retry</b>: button text when an upload error occurs<br>
     *   <b>quotaExceeded</b>: text used when user quota is exceeded<br>
     * <br>
     * The values of this object might be plain text or a key for an i18n file<br>
     */
    uploadText: {
      type: Object,
      default: function _default() {
        return {
          title: 'File Upload',
          upload: 'Upload',
          done: 'Done',
          retry: 'Try Again',
          quotaExceeded: 'Unfortunately you exceeded your quota, because you have only {space} of space left. Please remove some files to enable uploading.'
        };
      }
    },

    /**
     * current upload progress in percent per file<br>
     * array with current upload progress per file<br>
     * e.g. [11, 55, 100]
     */
    uploadPercentage: {
      type: Array,
      default: function _default() {
        return [];
      }
    },

    /**
     * define current free storage space (bytes)
     */
    userSpace: {
      type: Number,
      default: 10000000
    },

    /**
     * define rejected files<br>
     * array with filename(s)
     */
    rejectedFiles: {
      type: Array,
      default: function _default() {
        return [];
      }
    },

    /**
     * define uploaded files<br>
     * array with filename(s)
     */
    uploadedFiles: {
      type: Array,
      default: function _default() {
        return [];
      }
    }
  },
  computed: {
    buttonText: function buttonText() {
      if (this.currentStatus === 'initial' || this.currentStatus === 'saving') {
        return this.getI18nTerm(this.getLangLabel(this.uploadText.upload));
      }

      if (this.rejectedFiles.length) {
        return this.getI18nTerm(this.getLangLabel(this.uploadText.retry));
      }

      return this.getI18nTerm(this.getLangLabel(this.uploadText.done));
    },
    userQuotaExceeded: function userQuotaExceeded() {
      return this.userSpace < this.fileList.reduce(function (prev, curr) {
        return prev + curr.size;
      }, 0);
    }
  },
  methods: {
    convertSpace: function convertSpace(bytes, si) {
      var newBytes = bytes;
      var thresh = si ? 1000 : 1024;

      if (Math.abs(bytes) < thresh) {
        return "".concat(bytes, " B");
      }

      var units = si ? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] : ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
      var u = -1;

      do {
        newBytes /= thresh;
        u += 1;
      } while (Math.abs(newBytes) >= thresh && u < units.length - 1);

      return "".concat(newBytes.toFixed(1), " ").concat(units[u]);
    },
    getStatus: function getStatus(fileName) {
      if (this.uploadedFiles.includes(fileName)) {
        return 'success';
      }

      if (this.rejectedFiles.includes(fileName)) {
        return 'fail';
      }

      return '';
    },
    cancelUpload: function cancelUpload() {
      /**
       * Event emitted when cancel button is clicked
       *
       * @type {Event}
       */
      this.$emit('cancelUpload');
    },
    startUpload: function startUpload() {
      /**
       * Event emitted when upload button is clicked
       *
       * @type {Event}
       */
      this.$emit('startUpload');
    },
    removeFile: function removeFile(index) {
      /**
       * Event emitted when remove button on file entry is clicked
       *
       * @type {Event}
       * @property {number} index - index of the file entry
       */
      this.$emit('removeFile', index);
    }
  }
};var __vue_script__ = script;
/* template */

var __vue_render__ = function __vue_render__() {
  var _vm = this;

  var _h = _vm.$createElement;

  var _c = _vm._self._c || _h;

  return _c('BasePopUp', {
    attrs: {
      "show": !!_vm.fileList.length,
      "title": _vm.getI18nTerm(_vm.getLangLabel(_vm.uploadText.title))
    },
    on: {
      "close": _vm.cancelUpload
    }
  }, [_c('transition-group', {
    attrs: {
      "name": "list-complete"
    }
  }, [_vm.userQuotaExceeded ? _c('div', {
    key: "user-warning",
    staticClass: "base-uploader-user-warning"
  }, [_c('BaseIcon', {
    staticClass: "icon base-uploader-user-warning-icon",
    attrs: {
      "name": "attention"
    }
  }), _vm._v("\n      " + _vm._s(_vm.getI18nTerm(_vm.getLangLabel(_vm.uploadText.quotaExceeded), 1, {
    space: _vm.convertSpace(_vm.userSpace)
  })) + "\n    ")], 1) : _vm._e(), _vm._v(" "), _c('div', {
    key: "upload-area",
    staticClass: "popup-upload-area"
  }, [_c('transition-group', {
    staticClass: "transition",
    attrs: {
      "name": "bar-move"
    }
  }, _vm._l(_vm.fileList, function (file, index) {
    return _c('BaseProgressBar', {
      key: file.name,
      staticClass: "upload-bar",
      attrs: {
        "progress": _vm.uploadPercentage[index],
        "file-name": file.name,
        "file-size": _vm.userQuotaExceeded ? _vm.convertSpace(file.size) : '',
        "status": _vm.getStatus(file.name),
        "show-remove": _vm.currentStatus === 'initial' && _vm.fileList.length > 1
      },
      on: {
        "remove-item": function removeItem($event) {
          return _vm.removeFile(index);
        }
      }
    });
  }), 1)], 1)]), _vm._v(" "), _vm._t("default"), _vm._v(" "), _c('template', {
    slot: "button-row"
  }, [_vm.currentStatus === 'initial' || _vm.currentStatus === 'failed' ? _c('BaseButton', {
    staticClass: "base-upload-bar-button",
    attrs: {
      "text": _vm.getI18nTerm(_vm.cancelButtonText),
      "icon": 'remove',
      "icon-position": 'right',
      "icon-size": 'small'
    },
    on: {
      "clicked": _vm.cancelUpload
    }
  }) : _vm._e(), _vm._v(" "), _c('BaseButton', {
    ref: "uploadButton",
    staticClass: "base-upload-bar-button",
    attrs: {
      "text": _vm.buttonText,
      "icon": _vm.currentStatus !== 'saving' && _vm.currentStatus !== 'failed' ? 'check-mark' : '',
      "icon-position": 'right',
      "icon-size": 'small',
      "disabled": _vm.currentStatus === 'saving' || _vm.userQuotaExceeded
    },
    on: {
      "clicked": _vm.startUpload
    }
  }, [_vm.currentStatus === 'saving' ? _c('template', {
    slot: "right-of-text"
  }, [_c('span', {
    staticClass: "base-upload-bar-loader"
  }, [_c('BaseLoader')], 1)]) : _vm._e()], 2)], 1)], 2);
};

var __vue_staticRenderFns__ = [];
/* style */

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = "data-v-4cf8c822";
/* module identifier */

var __vue_module_identifier__ = "data-v-4cf8c822";
/* functional template */

var __vue_is_functional_template__ = false;
/* style inject */

/* style inject SSR */

/* style inject shadow dom */

var __vue_component__ = /*#__PURE__*/normalizeComponent.n({
  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);

var BaseUploadPopUp = __vue_component__;var Plugin = {
  install: function install(Vue) {
    normalizeComponent.r(Vue, BaseUploadPopUp);
  }
};
normalizeComponent.u(Plugin);exports.BaseUploadPopUp=BaseUploadPopUp;exports["default"]=Plugin;