import { FLAGS, useFeatureIsOn } from "@komi-app/flags-sdk";
import { useWindowSize } from "./useWindowSize";

/**
 * Audience and Campaign features are currently disabled on mobile.
 *
 * This hook checks to see if the flag should be disabled due to the user being on a small screen before returning the evaluated flag.
 * @param flag
 */
export function useAudienceAndCampaignFeatureOn(flag: FLAGS) {
  const isHidingOnMobileEnabled = useFeatureIsOn(
    FLAGS.FIX_SB_420_HIDE_AC_MOBILE
  );

  const { width } = useWindowSize();
  const isSmallScreen = width && width <= 768;

  const featureIsOn = useFeatureIsOn(flag);

  // if mobile block is enabled & on small screen
  if (isHidingOnMobileEnabled && isSmallScreen) {
    return false;
  }

  // if mobile block is disabled or not on small screen
  return featureIsOn;
}
