"use strict";

import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
import { CircleSnail } from 'react-native-progress';
import { BackHandler, StyleSheet, View } from 'react-native';
import { Colors } from "../Consts/index.js";
import { jsx as _jsx } from "react/jsx-runtime";
export default /*#__PURE__*/forwardRef((_, ref) => {
  const timeout = useRef(undefined);
  const [visible, setVisible] = useState(false);
  useImperativeHandle(ref, () => ({
    showLoading,
    hideLoading
  }));
  useEffect(() => {
    const backHandler = BackHandler.addEventListener('hardwareBackPress', () => {
      return visible;
    });
    return () => {
      backHandler.remove();
    };
  }, [visible]);

  /**
   * show loading
   * @param loading
   */
  const showLoading = ({
    duration = 10000
  }) => {
    setVisible(true);
    clearTimeout(timeout.current);
    timeout.current = setTimeout(() => {
      setVisible(false);
    }, duration);
  };

  /**
   * hidden loading
   */
  const hideLoading = () => {
    clearTimeout(timeout.current);
    setVisible(false);
  };
  if (visible) {
    return /*#__PURE__*/_jsx(View, {
      style: styles.container,
      children: /*#__PURE__*/_jsx(CircleSnail, {
        spinDuration: 2000,
        indeterminate: true,
        color: Colors.white,
        size: 64
      })
    });
  }
  return null;
});
const styles = StyleSheet.create({
  container: {
    ...StyleSheet.absoluteFillObject,
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#00000080'
  }
});
//# sourceMappingURL=LoadingView.js.map