'use strict';

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

var normalizeComponent = require('./normalize-component-6fa50395.js');
var ThemeMixin = require('./ThemeMixin-a2f817cd.js');
require('./svg-atom-d2541b7d.js');
require('./icon-atom-65241b51.js');
require('./hover-atom-17a12a07.js');
require('./tooltip-atom-8f536df5.js');
var IsDisabledMixin = require('./IsDisabledMixin-c3297ff2.js');
var fieldAtom = require('./field-atom-fe4b7c7b.js');
var labelMolecule = require('./label-molecule-9793dd9f.js');

var script = {
  name: 'FilePasteAtom',
  methods: {
    handlePaste: function handlePaste(e) {
      var files = e.clipboardData.files;

      if (!files || !files.length) {
        return;
      }

      this.$emit('change', files);
    }
  },
  beforeMount: function beforeMount() {
    document.addEventListener('paste', this.handlePaste, false);
  },
  beforeDestroy: function beforeDestroy() {
    document.removeEventListener('paste', this.handlePaste, false);
  },
  render: function render(createElement) {
    return createElement('div', this.$slots.default);
  }
};

/* script */
const __vue_script__ = script;

/* template */

  /* 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__ = undefined;
  /* style inject */
  
  /* style inject SSR */
  

  
  var FilePasteAtom = normalizeComponent.__vue_normalize__(
    {},
    __vue_inject_styles__,
    __vue_script__,
    __vue_scope_id__,
    __vue_is_functional_template__,
    __vue_module_identifier__,
    undefined,
    undefined
  );

//
var inputId = 1;
var script$1 = {
  name: 'VFileDropArea',
  props: {
    label: {
      type: String,
      default: null
    },
    tooltipLabel: {
      type: String,
      default: null
    },
    disabled: {
      type: Boolean,
      default: false
    },
    isUseClipboard: {
      type: Boolean,
      default: true
    }
  },
  data: function data() {
    return {
      // eslint-disable-next-line no-plusplus
      inputId: "v-file-drop-area-idx-".concat(inputId++)
    };
  },
  methods: {
    onPasteFiles: function onPasteFiles(files) {
      this.$emit('change', files);
    },
    onChange: function onChange(e) {
      this.$emit('change', e.target.files); // drop value for reselect file(s)
      // eslint-disable-next-line no-param-reassign

      e.target.value = '';
    },
    preventDrop: function preventDrop(e) {
      e.preventDefault();
      e.stopPropagation();
      return false;
    },
    handleDrop: function handleDrop(e) {
      if (this.isDisabled) {
        return this.preventDrop(e);
      }

      var files = this.getTransferFiles(e);
      this.$emit('change', files);
      return this.preventDrop(e);
    },
    getTransferFiles: function getTransferFiles(e) {
      var fileList = [];

      if (e.dataTransfer) {
        var dataTransfer = e.dataTransfer;

        if (dataTransfer.files && dataTransfer.files.length) {
          fileList = dataTransfer.files;
        } else if (dataTransfer.items && dataTransfer.items.length) {
          // During the drag even the dataTransfer.files is null
          // but Chrome implements some drag store,
          // which is accessible via dataTransfer.items
          fileList = dataTransfer.items;
        }
      } else if (e.target && e.target.files) {
        fileList = e.target.files;
      }

      return fileList;
    }
  },
  beforeMount: function beforeMount() {
    window.addEventListener('dragenter', this.preventDrop, false);
    window.addEventListener('dragleave', this.preventDrop, false);
    window.addEventListener('dragover', this.preventDrop, false);
    window.addEventListener('drop', this.handleDrop, false);
  },
  beforeDestroy: function beforeDestroy() {
    window.removeEventListener('dragenter', this.preventDrop, false);
    window.removeEventListener('dragleave', this.preventDrop, false);
    window.removeEventListener('dragover', this.preventDrop, false);
    window.removeEventListener('drop', this.handleDrop, false);
  },
  mixins: [ThemeMixin.ThemeMixin, IsDisabledMixin.IsDisabledMixin],
  components: {
    LabelMolecule: labelMolecule.LabelMolecule,
    FilePasteAtom: FilePasteAtom,
    FieldAtom: fieldAtom.FieldAtom
  },
  model: {
    event: 'change',
    prop: 'file'
  }
};

/* script */
const __vue_script__$1 = script$1;

/* template */
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('field-atom',[(_vm.label)?_c('label-molecule',{attrs:{"label":_vm.label,"tooltip-label":_vm.tooltipLabel,"disabled":_vm.disabled}}):_vm._e(),_vm._v(" "),_c('div',{staticClass:"v-file-drop-area-content",class:_vm.themeCssClass},[(_vm.isUseClipboard || !_vm.disabled)?_c('file-paste-atom',{on:{"change":_vm.onPasteFiles}}):_vm._e(),_vm._v(" "),_c('button',{staticClass:"v-file-drop-area-button",attrs:{"type":"button"}},[_c('label',{staticClass:"v-file-drop-area-label",attrs:{"for":_vm.inputId}},[_c('div',[_vm._t("default")],2),_vm._v(" "),_c('input',_vm._b({staticClass:"file-drop-area-input",attrs:{"id":_vm.inputId,"disabled":_vm.disabled,"type":"file"},on:{"change":_vm.onChange}},'input',_vm.$attrs,false))])])],1)],1)};
var __vue_staticRenderFns__ = [];

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

  
  var VFileDropArea = normalizeComponent.__vue_normalize__(
    { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
    __vue_inject_styles__$1,
    __vue_script__$1,
    __vue_scope_id__$1,
    __vue_is_functional_template__$1,
    __vue_module_identifier__$1,
    undefined,
    undefined
  );

exports.default = VFileDropArea;
