"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = FileUploaderItem;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _js = require("../../globals/js");

var _classnames = _interopRequireDefault(require("classnames"));

var _FileUploader = require("./FileUploader");

var _uniqueId = _interopRequireDefault(require("../../tools/uniqueId"));

var _excluded = ["uuid", "name", "status", "iconDescription", "onDelete", "invalid", "errorSubject", "errorBody"];
var prefix = _js.settings.prefix;

function FileUploaderItem(_ref) {
  var uuid = _ref.uuid,
      name = _ref.name,
      status = _ref.status,
      iconDescription = _ref.iconDescription,
      onDelete = _ref.onDelete,
      invalid = _ref.invalid,
      errorSubject = _ref.errorSubject,
      errorBody = _ref.errorBody,
      other = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var classes = (0, _classnames.default)("".concat(prefix, "--file__selected-file"), (0, _defineProperty2.default)({}, "".concat(prefix, "--file__selected-file--invalid"), invalid));
  return /*#__PURE__*/_react.default.createElement("span", (0, _extends2.default)({
    className: classes
  }, other), /*#__PURE__*/_react.default.createElement("p", {
    className: "".concat(prefix, "--file-filename")
  }, name), /*#__PURE__*/_react.default.createElement("span", {
    className: "".concat(prefix, "--file__state-container")
  }, /*#__PURE__*/_react.default.createElement(_FileUploader.Filename, {
    iconDescription: iconDescription,
    status: status,
    invalid: invalid,
    onKeyDown: function onKeyDown(evt) {
      /*
      if (matches(evt, [keys.Enter, keys.Space])) {
        if (status === 'edit') {
          onDelete(evt, { uuid });
        }
      }
      }*/
    },
    onClick: function onClick(evt) {
      if (status === 'edit') {
        onDelete(evt, {
          uuid: uuid
        });
      }
    }
  })), invalid && errorSubject && /*#__PURE__*/_react.default.createElement("div", {
    className: "".concat(prefix, "--form-requirement")
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "".concat(prefix, "--form-requirement__title")
  }, errorSubject), errorBody && /*#__PURE__*/_react.default.createElement("p", {
    className: "".concat(prefix, "--form-requirement__supplement")
  }, errorBody)));
}

FileUploaderItem.propTypes = {
  /**
   * Unique identifier for the file object
   */
  uuid: _propTypes.default.string.isRequired,

  /**
   * Name of the uploaded file
   */
  name: _propTypes.default.string,

  /**
   * Status of the file upload
   */
  status: _propTypes.default.oneOf(['uploading', 'edit', 'complete']),

  /**
   * Description of status icon (displayed in native tooltip)
   */
  iconDescription: _propTypes.default.string,

  /**
   * Specify whether the control is currently invalid.
   * Either a boolean in combination with `invalidText` or an `object`( eg. { message: "Message", …otherErrorProperties }) can be passed.
   */
  invalid: _propTypes.default.oneOfType([_propTypes.default.object, _propTypes.default.bool]),

  /**
   * Event handler that is called after removing a file from the file uploader
   * The event handler signature looks like `onDelete(evt, { uuid })`
   */
  onDelete: _propTypes.default.func,

  /**
   * Error message subject for an invalid file upload
   */
  errorSubject: _propTypes.default.string,

  /**
   * Error message body for an invalid file upload
   */
  errorBody: _propTypes.default.string
};
FileUploaderItem.defaultProps = {
  uuid: (0, _uniqueId.default)(),
  status: 'uploading',
  onDelete: function onDelete() {}
};