"use strict";

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

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

var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));

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

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

var _styles = require("@material-ui/core/styles");

var _helpers = require("../../helpers");

var _core = require("@material-ui/core");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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 useStyles = function useStyles(props, value) {
  return (0, _styles.makeStyles)(function (theme) {
    return {
      root: {
        maxWidth: '180px',
        border: "3px solid ".concat((0, _helpers.getColorByCorrectness)(props.correctness, theme, value)),
        borderRadius: '100px',
        outline: 'none',
        padding: "".concat(theme.spacing(0.5), "px ").concat(theme.spacing(1.5), "px"),
        color: "".concat((0, _helpers.getColorByCorrectness)(props.correctness, theme, value)),
        backgroundColor: "".concat((0, _helpers.getBackgroundColorByCorrectness)(props.correctness, theme))
      },
      inputFocused: {
        border: "3px solid ".concat((0, _helpers.getColorByCorrectness)(props.correctness, theme, 'some value'))
      }
    };
  });
};

function TestInputText(_ref) {
  var children = _ref.children,
      props = (0, _objectWithoutProperties2.default)(_ref, ["children"]);

  var _useState = (0, _react.useState)(props.userInput),
      _useState2 = (0, _slicedToArray2.default)(_useState, 2),
      value = _useState2[0],
      setValue = _useState2[1];

  var classes = useStyles(props, value)();

  var handleChange = function handleChange(e) {
    setValue(e.target.value);

    if (props.onChange) {
      props.onChange(e);
    }
  };

  return /*#__PURE__*/_react.default.createElement(_core.InputBase, {
    className: classes.root,
    classes: {
      focused: classes.inputFocused
    },
    value: value,
    onChange: handleChange,
    placeholder: value ? false : props.placeholder,
    disabled: props.readOnly,
    inputProps: {
      'aria-label': 'description'
    }
  }) // <input
  // className={classes.root}
  // placeholder={props.userInput || null}
  // value={props.userInput ? props.userInput : "Відповідь"}
  // readOnly={props.readOnly}
  // onChange={(event) => props.onChange(event)} />
  ;
}

TestInputText.defaultProps = {
  placeholder: 'Placeholder',
  userInput: undefined,
  correctness: undefined
};
var _default = TestInputText;
exports.default = _default;