"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _elements = require("@react-navigation/elements");
var _react = _interopRequireDefault(require("react"));
var _reactNative = require("react-native");
var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
var _theme = require("../../contexts/theme");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
const useSafeHeaderHeight = () => {
  try {
    return (0, _elements.useHeaderHeight)();
  } catch {
    return 100;
  }
};

/**
 * A wrapper component that provides keyboard-aware scrolling and safe area handling.
 *
 * This component creates a full-screen container with safe area insets and optional
 * keyboard avoidance behavior. It's designed to be used as a top-level wrapper for
 * screen content that may contain input fields or other interactive elements.
 *
 * @param children - The content to render inside the keyboard view
 * @param keyboardAvoiding - Whether to enable keyboard avoidance behavior. When true,
 *   the view will automatically adjust its content when the keyboard appears. Defaults to true.
 * @param scrollViewProps - Additional props to pass to the internal ScrollView component
 */
const KeyboardView = ({
  children,
  keyboardAvoiding = true,
  scrollViewProps
}) => {
  const {
    ColorPalette
  } = (0, _theme.useTheme)();
  const headerHeight = useSafeHeaderHeight();
  return /*#__PURE__*/_react.default.createElement(_reactNativeSafeAreaContext.SafeAreaView, {
    style: {
      flex: 1,
      backgroundColor: ColorPalette.brand.primaryBackground
    },
    edges: ['bottom', 'left', 'right']
  }, keyboardAvoiding ? /*#__PURE__*/_react.default.createElement(_reactNative.KeyboardAvoidingView, {
    style: {
      flex: 1
    },
    keyboardVerticalOffset: headerHeight,
    behavior: "padding"
  }, /*#__PURE__*/_react.default.createElement(_reactNative.ScrollView, _extends({
    contentContainerStyle: {
      flexGrow: 1
    },
    keyboardShouldPersistTaps: 'handled'
  }, scrollViewProps), children)) : /*#__PURE__*/_react.default.createElement(_reactNative.ScrollView, {
    contentContainerStyle: {
      flexGrow: 1
    },
    keyboardShouldPersistTaps: 'handled'
  }, children));
};
var _default = exports.default = KeyboardView;
//# sourceMappingURL=KeyboardView.js.map