import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import useActiveDatasetManager from "../use-active-dataset-manager";
import { useState, useEffect } from "react";
export default (function () {
  var _useActiveDatasetMana = useActiveDatasetManager(),
      _useActiveDatasetMana2 = _slicedToArray(_useActiveDatasetMana, 1),
      dm = _useActiveDatasetMana2[0];

  var _useState = useState(false),
      _useState2 = _slicedToArray(_useState, 2),
      isReady = _useState2[0],
      setIsReady = _useState2[1];

  useEffect(function () {
    if (!dm) return;

    function checkIfReady() {
      return _checkIfReady.apply(this, arguments);
    }

    function _checkIfReady() {
      _checkIfReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
        var newReadyState;
        return _regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                _context.next = 2;
                return dm.isReady();

              case 2:
                newReadyState = _context.sent;

                if (newReadyState !== isReady) {
                  setIsReady(newReadyState);
                }

              case 4:
              case "end":
                return _context.stop();
            }
          }
        }, _callee);
      }));
      return _checkIfReady.apply(this, arguments);
    }

    dm.on("connected", checkIfReady);
    dm.on("disconnected", checkIfReady);
    return function () {};
  }, [dm, isReady]);
  if (!dm) return false;
});