import { useState, useEffect } from 'react';
import { request } from 'utils/fetch';
import { api } from 'constants/config';
import {urlCacheReplace} from 'utils/utils';

export default function useLoadingPage(screenId) {
  const [loadingImageLoding, setLoadingImageLoading] = useState(true);
  const [loadingPage, setLoadingPage] = useState<string | null>(null);

  useEffect(() => {
    const getLoadingImg = async () => {
      const result = await request(urlCacheReplace(api.getScreentLoadingPage), { screenId: screenId });
      setLoadingImageLoading(false);
      if (result && result.loadingPage) {
        setLoadingPage(result.loadingPage);
      }
    };

    getLoadingImg();
  }, [screenId]);

  return { loadingImageLoding, loadingPage };
}
