"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.PromptInputTextarea = PromptInputTextarea;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _useTheme = require("../theme/use-theme.js");
var _context = require("./context.js");
var _jsxRuntime = require("react/jsx-runtime");
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); }
function PromptInputTextarea({
  placeholder,
  style,
  inputStyle,
  textInputProps,
  testID
}) {
  const {
    value,
    setValue,
    onSubmit,
    disabled,
    textareaRef,
    setCurrentHeight,
    isFullscreen,
    maxHeight,
    handleCompletionKey
  } = (0, _context.usePromptInput)();
  const theme = (0, _useTheme.useTheme)();
  const inputRef = (0, _react.useRef)(null);
  (0, _react.useImperativeHandle)(textareaRef, () => inputRef.current);
  const handleKeyPress = (0, _react.useCallback)(e => {
    textInputProps?.onKeyPress?.(e);
    const key = e.nativeEvent.key;
    if (handleCompletionKey && ['ArrowUp', 'ArrowDown', 'Enter', 'Escape'].includes(key)) {
      if (handleCompletionKey(key)) {
        e.preventDefault();
        return;
      }
    }
  }, [handleCompletionKey, textInputProps]);
  const handleContentSizeChange = (0, _react.useCallback)(e => {
    textInputProps?.onContentSizeChange?.(e);
  }, [textInputProps]);
  const textInput = /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
    style: [{
      width: '100%'
    }, isFullscreen && {
      flex: 1
    }],
    onLayout: e => setCurrentHeight(e.nativeEvent.layout.height),
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TextInput, {
      ref: inputRef,
      accessibilityLabel: "Message input",
      value: value,
      onChangeText: setValue,
      onSubmitEditing: onSubmit,
      onKeyPress: handleKeyPress,
      onContentSizeChange: handleContentSizeChange,
      multiline: true,
      editable: !disabled,
      scrollEnabled: isFullscreen,
      placeholder: placeholder,
      placeholderTextColor: theme.colors.textTertiary,
      style: [{
        width: '100%',
        fontSize: 16,
        color: theme.colors.text,
        paddingHorizontal: 14,
        backgroundColor: 'transparent',
        borderWidth: 0
      }, isFullscreen ? {
        flex: 1,
        paddingTop: 16,
        paddingBottom: 100
      } : {
        minHeight: 44,
        paddingVertical: 12,
        maxHeight,
        overflow: 'scroll'
      }, inputStyle],
      testID: testID,
      ...textInputProps
    })
  });
  if (isFullscreen) {
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
      style: [{
        flex: 1
      }, style],
      children: textInput
    });
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
    style: style,
    children: textInput
  });
}
PromptInputTextarea.displayName = 'PromptInputTextarea';
//# sourceMappingURL=Textarea.js.map