"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getWH = exports.default = void 0;

var _useSize3 = _interopRequireDefault(require("ahooks/es/useSize"));

var _forceUpdateHooks = _interopRequireDefault(require("parsec-hooks/lib/forceUpdateHooks"));

var _react = require("react");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var getWH = function getWH(id) {
  return new Promise(function (resolve) {
    var _ref = document.getElementById(id) || {},
        offsetWidth = _ref.offsetWidth,
        offsetHeight = _ref.offsetHeight;

    resolve({
      width: offsetWidth || 0,
      height: offsetHeight || 0
    });
  });
};

exports.getWH = getWH;

var _default = function _default(id) {
  var _useForceUpdate = (0, _forceUpdateHooks.default)(),
      forceUpdate = _useForceUpdate.forceUpdate;

  var _useSize = (0, _useSize3.default)(document.getElementById(id)),
      width = _useSize.width,
      height = _useSize.height;

  (0, _react.useEffect)(function () {
    if (height === undefined) {
      forceUpdate();
    }
  }, [width, height, forceUpdate]);
  return {
    width: width,
    height: height
  };
};

exports.default = _default;