"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = _interopRequireDefault(require("react"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var useTrackDuration = function useTrackDuration(audioRef) {
  var _React$useState = _react["default"].useState(0),
    _React$useState2 = (0, _slicedToArray2["default"])(_React$useState, 2),
    trackDuration = _React$useState2[0],
    setTrackDuration = _React$useState2[1];
  _react["default"].useEffect(function () {
    var audioNode = audioRef.current;
    if (!audioNode) {
      return;
    }
    var readyState = audioNode.readyState,
      duration = audioNode.duration;
    if (readyState > 0) {
      setTrackDuration(Math.round(duration));
    } else {
      audioNode.onloadedmetadata = function (e) {
        var el = e.target;
        setTrackDuration(Math.round(el.duration));
      };
    }
  }, [audioRef]);
  return trackDuration;
};
var _default = exports["default"] = useTrackDuration;