import { useSelector } from "react-redux";

/**
 * Hook to get the currently selected sub user from Redux state
 * @returns {Object|null} - The selected sub user object with { key, name, unit, mobile, fullname } or null
 */
export const useSelectedSubUser = () => {
  const selectedSubUser = useSelector(
    (state) => state.userSlice.selectedSubUser
  );
  return selectedSubUser;
};

/**
 * Hook to get only the selected sub user key
 * @returns {string|null} - The sub user key or null
 */
export const useSelectedSubUserKey = () => {
  const selectedSubUser = useSelector(
    (state) => state.userSlice.selectedSubUser
  );
  return selectedSubUser?.key || null;
};

export default useSelectedSubUser;

