'use strict';

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

var normalizeComponent = require('./normalize-component-6fa50395.js');
var ThemeMixin = require('./ThemeMixin-37dd1318.js');
var IsDisabledMixin = require('./IsDisabledMixin-c3297ff2.js');
var labelAtom = require('./label-atom-b52cf622.js');
var fieldAtom = require('./field-atom-d871ec6f.js');

//
var inputId = 1;
var script = {
  name: 'VFileDropArea',
  props: {
    label: {
      type: String,
      default: null
    }
  },
  data: function data() {
    return {
      // eslint-disable-next-line no-plusplus
      inputId: "v-file-drop-area-idx-".concat(inputId++)
    };
  },
  methods: {
    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: {
    FieldAtom: fieldAtom.FieldAtom,
    LabelAtom: labelAtom.LabelAtom
  },
  model: {
    event: 'change',
    prop: 'file'
  }
};

/* 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('field-atom',[(_vm.label)?_c('label-atom',{attrs:{"label":_vm.label}}):_vm._e(),_vm._v(" "),_c('div',{staticClass:"v-file-drop-area-content",class:_vm.themeCssClass},[_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,"type":"file"},on:{"change":_vm.onChange}},'input',_vm.$attrs,false))])])])],1)};
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 VFileDropArea = normalizeComponent.__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
  );

exports.default = VFileDropArea;
