/*   eslint-disable no-unused-vars, no-redeclare */
import React from "react";
import { NetInfoState } from "@react-native-community/netinfo";
import { NetworkStatusContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NetworkStatusContext";
import { isOnline } from "@applicaster/quick-brick-core/App/NetworkStatusProvider/utils";

/**
 * This hook returns connection type from RN NetInfo component or boolean for iConnected if justOnlineStatus flag is set
 * @param {boolean} justOnlineStatus - flag if to return boolean for isConnected
 *  Returns connection object from NetInfo or boolean if isConnected
 */

export function useConnectionInfo(justOnlineStatus: true): boolean;

export function useConnectionInfo(
  justOnlineStatus: false
): NetInfoState & { deviceStatus: NetStatus };

export function useConnectionInfo(
  justOnlineStatus: boolean
): boolean | (NetInfoState & { deviceStatus: NetStatus }) {
  const connectionInfo = React.useContext(
    NetworkStatusContext
  ) as NetInfoState & { deviceStatus: NetStatus };

  return justOnlineStatus ? isOnline(connectionInfo) === true : connectionInfo;
}
