"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _input = require("../input");
var _textarea = require("../textarea");
var _useFocusWithin = require("../hooks/use-focus-within");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const EditMode = /*#__PURE__*/(0, _react.forwardRef)(({
  onSubmit,
  onBlur,
  onKeyDown,
  onCancel,
  inputLabel,
  isMultiline,
  onChange,
  placeholder,
  value,
  options,
  inputClassName,
  shouldDisplayControls
}, ref) => {
  const [touched, setTouched] = (0, _react.useState)(false);
  const focusWithinProps = (0, _useFocusWithin.useFocusWithin)({
    onBlur
  });
  function handleChange(providedValue) {
    setTouched(true);
    if (onChange) {
      return onChange(providedValue);
    }
  }
  const inputProps = {
    children: null,
    'aria-label': inputLabel,
    onKeyDown,
    placeholder: placeholder || inputLabel,
    onChange: handleChange,
    onSubmit,
    onCancel,
    value,
    'test-id': 'edit-text-input',
    'tour-id': 'edit-text',
    autoFocus: true,
    touched
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("form", {
    className: "edit-text-form",
    "test-id": "edit-text-form",
    onSubmit: onSubmit,
    ref: ref,
    onBlur: focusWithinProps.onBlur,
    children: isMultiline ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_textarea.TextArea, {
      className: (0, _classnames.default)(inputClassName),
      shouldDisplayControls: false,
      rows: 3,
      ...inputProps,
      ...options
    }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_input.Input, {
      className: (0, _classnames.default)('edit-text-input', inputClassName, 'uil-input'),
      shouldDisplayControls: shouldDisplayControls,
      ...inputProps,
      ...options
    })
  });
});
EditMode.displayName = 'EditMode';
var _default = exports.default = EditMode;