'use client';

import { useAppSelector } from '../redux/hooks';
import { useState, useEffect } from 'react';
import { useSearchParams } from 'next/navigation';

export default function MobileAppToggler({
  children
}: {
  children: React.ReactNode;
}) {
  const searchParams = useSearchParams();
  const { isMobileApp } = useAppSelector((state) => state.root);
  const [isInIframe, setIsInIframe] = useState(false);

  useEffect(() => {
    if (window.frameElement) {
      setIsInIframe(true);
    }
  }, []);

  if (isMobileApp || isInIframe || searchParams.get('iframe') === 'true')
    return null;

  return <>{children}</>;
}
