'use strict';Object.defineProperty(exports,'__esModule',{value:true});var normalizeComponent=require('./normalize-component-d9981c57.js');require('./es.object.to-string-f27a75a8.js'),require('./es.regexp.to-string-5606f728.js'),require('./es.array.includes-3990bfec.js'),require('./es.number.constructor-daccdeab.js'),require('./regexp-exec-abstract-216cd44a.js'),require('./es.string.match-1a062dc1.js'),require('./es.object.values-1f44a4ee.js');var popUpLock=require('./popUpLock-85f8cf1c.js');require('./classof-819fc780.js'),require('./export-61511812.js'),require('./regexp-flags-abc49c4a.js'),require('./object-keys-12f2c5e5.js'),require('./object-set-prototype-of-dfa14cf5.js'),require('./string-multibyte-a2dff6e3.js');/**
 * Component allowing for the display of images or streaming of
 * audio and video (currently only hls format) and by using browser pdf viewer also pdfs
 *
 * CAVEAT: this component will be deprecated and replaced by BaseMediaCarousel!<br>
 * Usage not recommended!
 */

var script = {
  name: 'BaseMediaPreview',
  components: {
    BaseButton: function BaseButton() {
      return Promise.resolve().then(function(){return require('./BaseButton-0200f360.js')});
    },
    BaseIcon: function BaseIcon() {
      return Promise.resolve().then(function(){return require('./BaseIcon-1ed3bf6e.js')});
    },
    BaseImage: function BaseImage() {
      return Promise.resolve().then(function(){return require('./BaseImage-b2322064.js')});
    },
    BaseHlsVideo: function BaseHlsVideo() {
      return Promise.resolve().then(function(){return require('./BaseHlsVideo-82ed922c.js')});
    }
  },
  directives: {
    VueClickOutside: function VueClickOutside() {
      return Promise.resolve().then(function(){return require('./index-9dadef01.js')}).then(function(n){return n.i});
    }
  },
  mixins: [popUpLock.p],
  props: {
    /**
     * steer the display of the lightbox
     */
    showPreview: {
      type: Boolean,
      default: false
    },

    /**
     * url of the medium to be displayed
     */
    mediaUrl: {
      type: String,
      default: ''
    },

    /**
     * url of image for poster property in html5 video tag
     */
    mediaPosterUrl: {
      type: String,
      default: ''
    },

    /**
     * filename that will be displayed for the medium
     */
    displayName: {
      type: String,
      default: ''
    },

    /**
     * url for downloading the file
     */
    downloadUrl: {
      type: String,
      default: ''
    },

    /**
     * define the media type <br>
     *     options: 'image'|'video'|'audio'|'pdf'
     */
    mediaType: {
      type: String,
      default: '',
      validator: function validator(val) {
        return ['image', 'video', 'audio', 'pdf', ''].includes(val);
      }
    },

    /**
     * set height and with from outside
     */
    displaySize: {
      type: Object,
      default: function _default() {
        return {
          height: '720px',
          width: '1280px'
        };
      }
    },

    /**
     * define if download button should be shown and download be enabled
     */
    allowDownload: {
      type: Boolean,
      default: true
    },

    /**
     * define information texts for download and view (for pdfs) buttons
     */
    infoTexts: {
      type: Object,
      default: function _default() {
        return {
          download: 'Download',
          view: 'View'
        };
      }
    },

    /**
     * define how the image should be rotated (EXIF orientation values)
     */
    orientation: {
      type: Number,
      default: 0
    },

    /**
     * specify an image srcset as an array of objects in the form <br>
     *     { 'mediawidth': 'url' }
     */
    previews: {
      type: Array,
      default: function _default() {
        return [];
      }
    },

    /**
     * Additional info text below file name
     */
    additionalInfo: {
      type: Array,
      default: function _default() {
        return [];
      }
    },

    /**
     * set initial hls-video size
     */
    hlsStartLevel: {
      type: Number,
      default: undefined
    }
  },
  data: function data() {
    return {
      showInt: this.showPreview,
      // variable for display image error handling
      displayImage: true,
      targetName: 'mediaStage',
      isMobile: false
    };
  },
  computed: {
    fileType: function fileType() {
      if (this.mediaType) return this.mediaType;
      var docType = this.fileEnding; // check if image

      if (['png', 'gif', 'jpeg', 'jpg'].includes(docType.toLowerCase())) {
        return 'image';
      } // check if video


      if (['mp4', 'm3u8', 'ogg'].includes(docType.toLowerCase())) {
        return 'video';
      } // check if audio


      if (['mp3', 'wav', 'mpeg'].includes(docType.toLowerCase())) {
        return 'audio';
      } // check if pdf


      if (['pdf'].includes(docType.toLowerCase())) {
        return 'document';
      }

      return '';
    },
    fileName: function fileName() {
      if (this.displayName) {
        return this.displayName;
      }

      var match = this.downloadUrl.match(/([^/]+)$/);
      return match ? decodeURI(match[1]) : '';
    },
    fileEnding: function fileEnding() {
      var match = this.sourceUrl.match(/\w+\.(\w{2,4})$/);
      return match ? match[1] : '';
    },
    formatNotSupported: function formatNotSupported() {
      return !this.fileType;
    },
    sourceUrl: function sourceUrl() {
      var last = this.previews.length - 1;
      return this.previews && this.previews[last] ? Object.values(this.previews[last])[0] : this.mediaUrl;
    }
  },
  watch: {
    showPreview: function showPreview(val) {
      this.showInt = val;
      this.displayImage = true;
    }
  },
  mounted: function mounted() {
    this.isMobile = window.innerWidth <= 640;
  },
  methods: {
    clickOutside: function clickOutside(event) {
      // for some reason clickOutside is also triggered when opening the box
      // --> to prevent immediate closure
      if (event.target.className === 'base-media-preview-image-stage') {
        /**
         * triggered on clicking outside image area
         *
         * @event hide-preview
         * @type { None }
         *
         */
        this.$emit('hide-preview');
      }
    },
    download: function download() {
      // check again if user is allowed to download
      if (this.allowDownload) {
        /**
         * download button clicked
         *
         * @event download
         * @type { Object }
         *
         */
        this.$emit('download', {
          url: this.downloadUrl || this.mediaUrl,
          name: this.fileName
        });
      }
    },
    openPdf: function openPdf() {
      window.open(this.mediaUrl);
    }
  }
};
/**
 * emitted when a close action is triggered
 *
 * @event hide-preview
 * @type none
 *
 */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 _vm.showInt ? _c('div', {
    staticClass: "base-media-preview-background"
  }, [_vm._ssrNode("<div class=\"base-media-preview-close\" data-v-0ddac16a>", "</div>", [_c('base-icon', {
    staticClass: "base-media-preview-close-icon",
    attrs: {
      "name": "remove"
    }
  })], 1), _vm._ssrNode(" "), _c('transition', {
    attrs: {
      "name": "grow"
    }
  }, [_c('div', {
    ref: "mediaStage",
    staticClass: "base-media-preview-image-stage"
  }, [_vm.displayImage && _vm.fileType === 'image' ? _c('BaseImage', {
    directives: [{
      name: "vue-click-outside",
      rawName: "v-vue-click-outside.prevent",
      value: _vm.clickOutside,
      expression: "clickOutside",
      modifiers: {
        "prevent": true
      }
    }],
    class: ['base-media-preview-image', 'base-media-preview-rotation-' + _vm.orientation.toString()],
    style: _vm.displaySize,
    attrs: {
      "srcset": _vm.previews,
      "src": _vm.sourceUrl
    },
    on: {
      "error": function error($event) {
        _vm.displayImage = false;
      }
    }
  }) : _vm.fileType === 'image' && !_vm.displayImage ? _c('div', {
    staticClass: "base-media-preview-error"
  }, [_vm._v("\n        An error occurred displaying this image.\n      ")]) : _vm.fileType === 'video' ? _c('base-hls-video', {
    staticClass: "base-media-preview-video",
    attrs: {
      "display-size": _vm.displaySize,
      "media-url": _vm.mediaUrl,
      "start-level": _vm.hlsStartLevel,
      "media-poster-url": _vm.mediaPosterUrl
    }
  }) : _vm.fileType === 'audio' ? _c('audio', {
    staticClass: "base-media-preview__audio",
    attrs: {
      "controls": ""
    }
  }, [_vm._v("\n        Your browser does not support the audio tag.\n        "), _c('source', {
    attrs: {
      "src": _vm.mediaUrl,
      "type": "audio/mpeg"
    }
  })]) : _c('div', {
    staticClass: "base-media-preview-not-supported base-media-preview-error"
  }, [_c('p', {
    staticClass: "base-media-preview-not-supported-file-name"
  }, [_vm._v("\n          " + _vm._s(_vm.fileName) + "\n        ")]), _vm._v(" "), _c('div', {
    staticClass: "base-media-preview-not-supported-buttons"
  }, [_vm.allowDownload ? _c('BaseButton', {
    staticClass: "base-media-preview__button base-media-preview-not-supported-button",
    attrs: {
      "text": _vm.infoTexts.download,
      "icon": "download",
      "icon-position": "right",
      "icon-size": "large"
    },
    on: {
      "clicked": _vm.download
    }
  }) : _vm._e(), _vm._v(" "), !_vm.isMobile && _vm.fileEnding === 'pdf' ? _c('BaseButton', {
    staticClass: "base-media-preview__button base-media-preview-not-supported-button",
    attrs: {
      "text": _vm.infoTexts.view,
      "icon": "eye",
      "icon-position": "right",
      "icon-size": "large"
    },
    on: {
      "clicked": function clicked($event) {
        return _vm.openPdf();
      }
    }
  }) : _vm._e()], 1), _vm._v(" "), _vm._l(_vm.additionalInfo, function (textline) {
    return _c('p', {
      key: textline,
      staticClass: "base-media-preview__not-supported-additional"
    }, [_vm._v("\n          " + _vm._s(textline) + "\n        ")]);
  })], 2), _vm._v(" "), _vm.fileEnding !== 'pdf' && !_vm.formatNotSupported ? _c('div', {
    staticClass: "base-media-preview-info"
  }, [_c('div', {
    staticClass: "base-media-preview__info-text-wrapper"
  }, [_c('p', {
    staticClass: "base-media-preview-info-text"
  }, [_vm._v("\n            " + _vm._s(_vm.fileName) + "\n          ")]), _vm._v(" "), _vm.additionalInfo.length ? _vm._l(_vm.additionalInfo, function (textline) {
    return _c('p', {
      key: textline,
      staticClass: "base-media-preview__info-text-additional"
    }, [_vm._v("\n              " + _vm._s(textline) + "\n            ")]);
  }) : _vm._e()], 2), _vm._v(" "), _vm.allowDownload ? _c('BaseButton', {
    staticClass: "base-media-preview__button",
    attrs: {
      "text": _vm.infoTexts.download,
      "icon": "download",
      "icon-position": "right",
      "icon-size": "large"
    },
    on: {
      "clicked": _vm.download
    }
  }) : _vm._e()], 1) : _vm._e()], 1)])], 2) : _vm._e();
};

var __vue_staticRenderFns__ = [];
/* style */

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = "data-v-0ddac16a";
/* module identifier */

var __vue_module_identifier__ = "data-v-0ddac16a";
/* 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 BaseMediaPreview = __vue_component__;var Plugin = {
  install: function install(Vue) {
    normalizeComponent.r(Vue, BaseMediaPreview);
  }
};
normalizeComponent.u(Plugin);exports.BaseMediaPreview=BaseMediaPreview;exports["default"]=Plugin;