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); }
import React, { useState } from "react";
import { StatusBar, RefreshControl } from "react-native";
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
import { pearl } from "../../../pearl";
import { SafeAreaView, View as MotiView } from "moti";
import { MOTI_PROPS } from "../../../hooks/utils/utils";
import { useTheme } from "../../../hooks/useTheme";
import _ from "lodash";
// 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.memo( /*#__PURE__*/React.forwardRef(({
  children,
  size,
  variant,
  scrollable,
  showScrollBar,
  onPullToRefresh,
  refreshIndicatorColors,
  refreshProgressBackgroundColor,
  refreshProgressViewOffset,
  refreshIndicatorSize,
  refreshTintColor,
  refreshTitle,
  refreshTitleColor,
  ...props
}, ref) => {
  const {
    colorMode
  } = useTheme();
  const [refreshing, setRefreshing] = useState(false);
  const animationProps = _.pick(props, MOTI_PROPS);
  const nativeProps = _.omit(props, [...MOTI_PROPS, "style"]);

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

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