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

  var _useState = useState({
    summaryLoading: true,
    summary: {}
  }),
      _useState2 = _slicedToArray(_useState, 2),
      retVal = _useState2[0],
      setRetVal = _useState2[1];

  useEffect(function () {
    if (!dm) return {
      summaryLoading: true,
      summary: {}
    };

    function loadSummary() {
      dm.getSummary().then(function (summary) {
        setRetVal({
          summaryLoading: false,
          summary: summary
        });
      });
    }

    loadSummary();
    dm.on("summary-changed", loadSummary);
    return function () {
      dm.off("summary-changed", loadSummary);
    };
  }, [dm]);
  return retVal;
});