"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.FileInput = void 0;

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

function _typeof(obj) { "@babel/helpers - typeof"; 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 _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var FileInput = function FileInput(_ref) {
  var id = _ref.id,
      label = _ref.label,
      ariaDescribedByText = _ref.ariaDescribedByText,
      onChange = _ref.onChange;
  // USWDS File Input is managed by JS (not exclusive CSS)
  // We need to import the distributed JS code. It runs immediately
  // after being parsed, and searches for DOM elements with the
  // appriopriate HTML attributes. React constantly mounts/unmounts
  // DOM nodes. To get around this, we dynamically import USWDS every
  // render. However, browsers cache the module and so subsequent
  // imports don't trigger the code to execute again. To get around
  // this, we must delete the module from the cache.
  (0, _react.useEffect)(function () {
    delete require.cache[require.resolve('uswds/dist/js/uswds')]; // @ts-ignore

    Promise.resolve().then(function () {
      return _interopRequireWildcard(require('uswds/dist/js/uswds'));
    });
  }, []);
  return /*#__PURE__*/_react.default.createElement("label", {
    htmlFor: id
  }, label, ariaDescribedByText && /*#__PURE__*/_react.default.createElement("span", {
    id: "".concat(id, "-aria-describedby")
  }, " ", ariaDescribedByText), /*#__PURE__*/_react.default.createElement("input", {
    id: id,
    type: "file",
    className: "usa-file-input",
    "aria-describedby": ariaDescribedByText ? "".concat(id, "-aria-describedby") : undefined,
    onChange: onChange
  }));
};

exports.FileInput = FileInput;