import "core-js/modules/es7.symbol.async-iterator";
import "core-js/modules/es6.symbol";
import "core-js/modules/es6.object.assign";
import "core-js/modules/web.dom.iterable";
import "core-js/modules/es6.array.iterator";
import "core-js/modules/es6.object.keys";
import "core-js/modules/es6.object.set-prototype-of";
import "core-js/modules/es6.function.name";
import "core-js/modules/es6.regexp.split";

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { EuiButtonEmpty } from '../../button';
import { EuiIcon } from '../../icon';
export var EuiFilePicker =
/*#__PURE__*/
function (_Component) {
  _inherits(EuiFilePicker, _Component);

  function EuiFilePicker(props) {
    var _this;

    _classCallCheck(this, EuiFilePicker);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(EuiFilePicker).call(this, props));

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleChange", function () {
      if (_this.fileInput.files && _this.fileInput.files.length > 1) {
        _this.setState({
          promptText: "".concat(_this.fileInput.files.length, " files selected")
        });
      } else if (_this.fileInput.files.length === 0) {
        _this.setState({
          promptText: _this.props.initialPromptText
        });
      } else {
        _this.setState({
          promptText: _this.fileInput.value.split('\\').pop()
        });
      }

      var onChange = _this.props.onChange;

      if (onChange) {
        onChange(_this.fileInput.files);
      }
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "removeFiles", function (e) {
      e.stopPropagation();
      e.preventDefault();
      _this.fileInput.value = null;

      _this.handleChange();
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "showDrop", function () {
      if (!_this.props.disabled) {
        _this.setState({
          isHoveringDrop: true
        });
      }
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "hideDrop", function () {
      _this.setState({
        isHoveringDrop: false
      });
    });

    _this.state = {
      promptText: _this.props.initialPromptText,
      isHoveringDrop: false
    };
    return _this;
  }

  _createClass(EuiFilePicker, [{
    key: "render",
    value: function render() {
      var _this2 = this;

      var _this$props = this.props,
          id = _this$props.id,
          name = _this$props.name,
          initialPromptText = _this$props.initialPromptText,
          className = _this$props.className,
          disabled = _this$props.disabled,
          compressed = _this$props.compressed,
          onChange = _this$props.onChange,
          rest = _objectWithoutProperties(_this$props, ["id", "name", "initialPromptText", "className", "disabled", "compressed", "onChange"]);

      var classes = classNames('euiFilePicker', {
        'euiFilePicker__showDrop': this.state.isHoveringDrop,
        'euiFilePicker--compressed': compressed,
        'euiFilePicker-hasFiles': this.state.promptText !== initialPromptText
      }, className);
      var clearButton;

      if (this.state.promptText !== initialPromptText) {
        if (compressed) {
          clearButton = React.createElement("button", {
            "aria-label": "Clear selected files",
            className: "euiFilePicker__clearButton",
            onClick: this.removeFiles
          }, React.createElement(EuiIcon, {
            className: "euiFilePicker__clearIcon",
            type: "cross"
          }));
        } else {
          clearButton = React.createElement(EuiButtonEmpty, {
            "aria-label": "Clear selected files",
            className: "euiFilePicker__clearButton",
            size: "xs",
            onClick: this.removeFiles
          }, "Remove");
        }
      } else {
        clearButton = null;
      }

      return React.createElement("div", {
        className: classes
      }, React.createElement("div", {
        className: "euiFilePicker__wrap"
      }, React.createElement("input", _extends({
        type: "file",
        id: id,
        name: name,
        className: "euiFilePicker__input",
        onChange: this.handleChange,
        ref: function ref(input) {
          _this2.fileInput = input;
        },
        onDragOver: this.showDrop,
        onDragLeave: this.hideDrop,
        onDrop: this.hideDrop,
        disabled: disabled
      }, rest)), React.createElement("div", {
        className: "euiFilePicker__prompt"
      }, React.createElement(EuiIcon, {
        className: "euiFilePicker__icon",
        type: "importAction",
        size: compressed ? 'm' : 'l',
        "aria-hidden": "true"
      }), React.createElement("div", {
        className: "euiFilePicker__promptText"
      }, this.state.promptText), clearButton)));
    }
  }]);

  return EuiFilePicker;
}(Component);

_defineProperty(EuiFilePicker, "propTypes", {
  id: PropTypes.string,
  name: PropTypes.string,
  className: PropTypes.string,

  /**
   * The content that appears in the dropzone if no file is attached
   */
  initialPromptText: PropTypes.node,

  /**
   * Use as a callback to access the HTML FileList API
   */
  onChange: PropTypes.func,

  /**
   * Reduces the size to a typical (compressed) input
   */
  compressed: PropTypes.bool
});

_defineProperty(EuiFilePicker, "defaultProps", {
  initialPromptText: 'Select or drag and drop a file',
  compressed: false
});

EuiFilePicker.__docgenInfo = {
  "description": "",
  "methods": [{
    "name": "handleChange",
    "docblock": null,
    "modifiers": [],
    "params": [],
    "returns": null
  }, {
    "name": "removeFiles",
    "docblock": null,
    "modifiers": [],
    "params": [{
      "name": "e",
      "type": null
    }],
    "returns": null
  }, {
    "name": "showDrop",
    "docblock": null,
    "modifiers": [],
    "params": [],
    "returns": null
  }, {
    "name": "hideDrop",
    "docblock": null,
    "modifiers": [],
    "params": [],
    "returns": null
  }],
  "displayName": "EuiFilePicker",
  "props": {
    "initialPromptText": {
      "defaultValue": {
        "value": "'Select or drag and drop a file'",
        "computed": false
      },
      "type": {
        "name": "node"
      },
      "required": false,
      "description": "The content that appears in the dropzone if no file is attached"
    },
    "compressed": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "type": {
        "name": "bool"
      },
      "required": false,
      "description": "Reduces the size to a typical (compressed) input"
    },
    "id": {
      "type": {
        "name": "string"
      },
      "required": false,
      "description": ""
    },
    "name": {
      "type": {
        "name": "string"
      },
      "required": false,
      "description": ""
    },
    "className": {
      "type": {
        "name": "string"
      },
      "required": false,
      "description": ""
    },
    "onChange": {
      "type": {
        "name": "func"
      },
      "required": false,
      "description": "Use as a callback to access the HTML FileList API"
    }
  }
};