"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = require("react");
var _currentSiteCloudId = require("../../services/current-site-cloud-id");
var useCurrentSiteCloudId = function useCurrentSiteCloudId() {
  var _useState = (0, _react.useState)(undefined),
    _useState2 = (0, _slicedToArray2.default)(_useState, 2),
    cloudId = _useState2[0],
    setCloudId = _useState2[1];
  var _useState3 = (0, _react.useState)(true),
    _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
    isLoading = _useState4[0],
    setIsLoading = _useState4[1];
  (0, _react.useEffect)(function () {
    var cancelled = false;
    setIsLoading(true);
    void (0, _currentSiteCloudId.getCurrentSiteCloudId)().then(function (id) {
      if (!cancelled) {
        setCloudId(id);
      }
    }).finally(function () {
      if (!cancelled) {
        setIsLoading(false);
      }
    });
    return function () {
      cancelled = true;
    };
  }, []);
  return {
    cloudId: cloudId,
    isLoading: isLoading
  };
};
var _default = exports.default = useCurrentSiteCloudId;