import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import { useEffect, useState } from 'react';
import { getCurrentSiteCloudId } from '../../services/current-site-cloud-id';
export { CURRENT_SITE_CLOUD_ID_LOCAL_STORAGE_KEY, CURRENT_SITE_CLOUD_ID_STORAGE_ITEM_KEY, currentSiteCloudIdService, getCurrentSiteCloudId, getCachedCurrentSiteCloudIdAndRefresh } from '../../services/current-site-cloud-id';
var useCurrentSiteCloudId = function useCurrentSiteCloudId() {
  var _useState = useState(undefined),
    _useState2 = _slicedToArray(_useState, 2),
    cloudId = _useState2[0],
    setCloudId = _useState2[1];
  var _useState3 = useState(true),
    _useState4 = _slicedToArray(_useState3, 2),
    isLoading = _useState4[0],
    setIsLoading = _useState4[1];
  useEffect(function () {
    var cancelled = false;
    setIsLoading(true);
    void getCurrentSiteCloudId().then(function (id) {
      if (!cancelled) {
        setCloudId(id);
      }
    }).finally(function () {
      if (!cancelled) {
        setIsLoading(false);
      }
    });
    return function () {
      cancelled = true;
    };
  }, []);
  return {
    cloudId: cloudId,
    isLoading: isLoading
  };
};
export default useCurrentSiteCloudId;