"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _reactNativeKeyboardAwareScrollView = require("react-native-keyboard-aware-scroll-view");
var _pearl = require("../../../pearl");
var _moti = require("moti");
var _utils = require("../../../hooks/utils/utils");
var _useTheme = require("../../../hooks/useTheme");
var _lodash = _interopRequireDefault(require("lodash"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
// TODO: Add Custom Pull-to-Refresh components and animations
/**
 * CustomScreen is a functional component that returns a SafeAreaView component with specific styles based on the props.
 * It uses the forwardRef function from React to pass the ref to the KeyboardAwareScrollView component.
 * @param children The children to render inside the KeyboardAwareScrollView
 * @param size The size of the Screen component
 * @param variant The variant of the Screen component
 * @param scrollable Whether the screen is scrollable
 * @param showScrollBar Whether to show the vertical scrollbar if the Screen is scrollable
 * @param onPullToRefresh Method to execute when a pull-to-refresh action is performed
 * @param refreshIndicatorColors The colors (at least one) that will be used to draw the refresh indicator (Android only)
 * @param refreshProgressBackgroundColor Progress view top offset
 * @param refreshProgressViewOffset The background color of the refresh indicator
 * @param refreshIndicatorSize Size of the refresh indicator (Android only)
 * @param refreshTintColor The color of the refresh indicator (iOS only)
 * @param refreshTitle The title displayed under the refresh indicator (iOS only)
 * @param refreshTitleColor The color of the refresh indicator title (iOS only)
 * @returns A SafeAreaView component with a KeyboardAwareScrollView component inside
 */
const CustomScreen = /*#__PURE__*/_react.default.memo( /*#__PURE__*/_react.default.forwardRef(({
  children,
  size,
  variant,
  scrollable,
  showScrollBar,
  onPullToRefresh,
  refreshIndicatorColors,
  refreshProgressBackgroundColor,
  refreshProgressViewOffset,
  refreshIndicatorSize,
  refreshTintColor,
  refreshTitle,
  refreshTitleColor,
  ...props
}, ref) => {
  const {
    colorMode
  } = (0, _useTheme.useTheme)();
  const [refreshing, setRefreshing] = (0, _react.useState)(false);
  const animationProps = _lodash.default.pick(props, _utils.MOTI_PROPS);
  const nativeProps = _lodash.default.omit(props, [..._utils.MOTI_PROPS, "style"]);

  /**
   * Function to execute when a pull-to-refresh action is performed
   */
  const onRefresh = _react.default.useCallback(async () => {
    if (onPullToRefresh) {
      setRefreshing(true);
      try {
        await onPullToRefresh();
      } catch (error) {
        console.error(error);
      } finally {
        setRefreshing(false);
      }
    }
  }, [onPullToRefresh]);
  const mainView = scrollable ? /*#__PURE__*/_react.default.createElement(_reactNativeKeyboardAwareScrollView.KeyboardAwareScrollView, _extends({}, nativeProps, {
    enableOnAndroid: true,
    ref: ref,
    bounces: true,
    extraHeight: 100,
    showsVerticalScrollIndicator: showScrollBar,
    contentContainerStyle: {
      flexGrow: 1
    },
    refreshControl: onPullToRefresh ? /*#__PURE__*/_react.default.createElement(_reactNative.RefreshControl, {
      colors: refreshIndicatorColors,
      progressBackgroundColor: refreshProgressBackgroundColor,
      progressViewOffset: refreshProgressViewOffset,
      size: refreshIndicatorSize,
      tintColor: refreshTintColor,
      title: refreshTitle,
      titleColor: refreshTitleColor,
      refreshing: refreshing,
      onRefresh: onRefresh
    }) : undefined
  }), /*#__PURE__*/_react.default.createElement(_moti.View, _extends({}, animationProps, {
    style: props.style
  }), children)) : /*#__PURE__*/_react.default.createElement(_moti.View, _extends({}, animationProps, {
    style: [{
      flex: 1
    }, props.style]
  }), children);
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_reactNative.StatusBar, {
    backgroundColor: (animationProps.animate ?? {}).backgroundColor ?? (props.style ?? {}).backgroundColor,
    barStyle: colorMode === "light" ? "dark-content" : "light-content"
  }), /*#__PURE__*/_react.default.createElement(_moti.SafeAreaView, {
    style: {
      flex: 1
    }
  }, mainView));
}));

/** A layout component that you can use to wrap all the views in your app. */
const Screen = (0, _pearl.pearl)(CustomScreen, {
  componentName: "Screen",
  type: "atom",
  animatable: true
});
Screen.displayName = "Screen";
var _default = exports.default = Screen;
//# sourceMappingURL=screen.js.map