"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.AltDialog = void 0;

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

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

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

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

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

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

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

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

var _DialogContent = _interopRequireDefault(require("@material-ui/core/DialogContent"));

var _ArrowBackIos = _interopRequireDefault(require("@material-ui/icons/ArrowBackIos"));

var _TextField = _interopRequireDefault(require("@material-ui/core/TextField"));

var _DialogActions = _interopRequireDefault(require("@material-ui/core/DialogActions"));

var _Button = _interopRequireDefault(require("@material-ui/core/Button"));

var _Dialog = _interopRequireDefault(require("@material-ui/core/Dialog"));

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

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

var AltDialog = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2["default"])(AltDialog, _React$Component);

  var _super = _createSuper(AltDialog);

  function AltDialog(props) {
    var _this;

    (0, _classCallCheck2["default"])(this, AltDialog);
    _this = _super.call(this, props);
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "closeDialog", function () {
      var allDialogs = document.querySelectorAll('#text-dialog');
      allDialogs.forEach(function (s) {
        return s.remove();
      });
    });
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onDone", function () {
      var onDone = _this.props.onDone;
      var value = _this.state.value;
      onDone(value);

      _this.closeDialog();
    });
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleOverflow", function () {
      document.body.style.removeProperty('overflow');
    });
    var alt = props.alt;
    _this.state = {
      value: alt
    };
    return _this;
  }

  (0, _createClass2["default"])(AltDialog, [{
    key: "render",
    value: function render() {
      var _this2 = this;

      var value = this.state.value;
      return /*#__PURE__*/_react["default"].createElement(_Dialog["default"], {
        open: true,
        disablePortal: true,
        onClose: this.closeDialog,
        id: "text-dialog",
        hideBackdrop: true,
        disableScrollLock: true,
        onEntered: this.handleOverflow
      }, /*#__PURE__*/_react["default"].createElement(_DialogContent["default"], null, /*#__PURE__*/_react["default"].createElement("div", {
        style: {
          display: 'flex'
        }
      }, /*#__PURE__*/_react["default"].createElement(_ArrowBackIos["default"], {
        style: {
          paddingTop: '6px'
        }
      }), /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
        multiline: true,
        placeholder: 'Enter an Alt Text description of this image',
        helperText: 'Users with visual limitations rely on Alt Text, since screen readers cannot otherwise describe the contents of an image.',
        value: value,
        onChange: function onChange(event) {
          return _this2.setState({
            value: event.target.value
          });
        },
        FormHelperTextProps: {
          style: {
            fontSize: 14
          }
        }
      }))), /*#__PURE__*/_react["default"].createElement(_DialogActions["default"], null, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
        onClick: this.onDone
      }, "Done")));
    }
  }]);
  return AltDialog;
}(_react["default"].Component);

exports.AltDialog = AltDialog;
(0, _defineProperty2["default"])(AltDialog, "propTypes", {
  onDone: _propTypes["default"].func.isRequired,
  alt: _propTypes["default"].string
});
var _default = AltDialog;
exports["default"] = _default;
//# sourceMappingURL=alt-dialog.js.map