import { useEffect } from 'react';
import { useGlobal } from './useGlobal';

let isMounted = false;

export const useIsProduction = () => {
  const [isProduction, setIsProduction] = useGlobal<boolean>('IS_PRODUCTION', true);

  useEffect(() => {
    if (!isMounted) {
      isMounted = true;
      const isProduction = window.location.protocol.includes('https');
      setIsProduction(isProduction);
      if (!isProduction) {
        document.title = 'Dev ' + document.title;
      }
    }
  }, []);

  return isProduction;
};
