import { useNavigation } from '@react-navigation/native';
import { NavigationRoutes } from 'navigation/enum';
import { resetToMagicLinkConfirm } from 'navigation/reset';
import { useCallback } from 'react';
import { ParamsProps, Routing } from './types';

export const useRouting = (): Routing => {
  const { navigate, goBack, dispatch } = useNavigation();

  const navigateTo = (nav: any, params?: any) => {
    navigate(nav, params);
  };
  const navigateBack = useCallback(() => {
    goBack();
  }, [goBack]);

  const toLanding = (params: ParamsProps) => {
    dispatch(
      resetToMagicLinkConfirm({
        email: params.email,
        verificationCode: params?.verificationCode,
      })
    );
  };

  const openRoom = useCallback(
    (id) => {
      navigate(NavigationRoutes.Room, { roomId: id });
    },
    [navigate]
  );
  return {
    toLanding,
    navigateTo,
    routeSegments: [],
    params: null,
    openRoom,
    navigateBack,
  };
};
