import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["uuid", "name", "status", "iconDescription", "onDelete", "invalid", "errorSubject", "errorBody"];

/**
 * Copyright IBM Corp. 2016, 2018
 *
 * This source code is licensed under the Apache-2.0 license found in the
 * LICENSE file in the root directory of this source tree.
 */
import React from 'react';
import PropTypes from 'prop-types';
import { settings } from '../../globals/js';
import classNames from 'classnames';
import { Filename } from './FileUploader'; //import { keys, matches } from '../../internal/keyboard';

import uid from '../../tools/uniqueId';
var prefix = settings.prefix;
export default 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 = _objectWithoutProperties(_ref, _excluded);

  var classes = classNames("".concat(prefix, "--file__selected-file"), _defineProperty({}, "".concat(prefix, "--file__selected-file--invalid"), invalid));
  return /*#__PURE__*/React.createElement("span", _extends({
    className: classes
  }, other), /*#__PURE__*/React.createElement("p", {
    className: "".concat(prefix, "--file-filename")
  }, name), /*#__PURE__*/React.createElement("span", {
    className: "".concat(prefix, "--file__state-container")
  }, /*#__PURE__*/React.createElement(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.createElement("div", {
    className: "".concat(prefix, "--form-requirement")
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "--form-requirement__title")
  }, errorSubject), errorBody && /*#__PURE__*/React.createElement("p", {
    className: "".concat(prefix, "--form-requirement__supplement")
  }, errorBody)));
}
FileUploaderItem.propTypes = {
  /**
   * Unique identifier for the file object
   */
  uuid: PropTypes.string.isRequired,

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

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

  /**
   * Description of status icon (displayed in native tooltip)
   */
  iconDescription: PropTypes.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.oneOfType([PropTypes.object, PropTypes.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.func,

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

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