"use strict";

var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  return mod && mod.__esModule ? mod : {
    "default": mod
  };
};

Object.defineProperty(exports, "__esModule", {
  value: true
});

var css_animation_1 = __importDefault(require("@ant-design/css-animation"));

var raf_1 = __importDefault(require("raf"));

function animate(node, show, done) {
  var height;
  var requestAnimationFrameId;
  return css_animation_1["default"](node, 'dmc-collapse-animation', {
    start: function start() {
      if (!show) {
        node.style.height = node.offsetHeight + "px";
        node.style.opacity = '1';
      } else {
        height = node.offsetHeight;
        node.style.height = '0px';
        node.style.opacity = '0';
      }
    },
    active: function active() {
      if (requestAnimationFrameId) {
        raf_1["default"].cancel(requestAnimationFrameId);
      }

      requestAnimationFrameId = raf_1["default"](function () {
        node.style.height = (show ? height : 0) + "px";
        node.style.opacity = show ? '1' : '0';
      });
    },
    end: function end() {
      if (requestAnimationFrameId) {
        raf_1["default"].cancel(requestAnimationFrameId);
      }

      node.style.height = '';
      node.style.opacity = '';
      done();
    }
  });
}

var animation = {
  enter: function enter(node, done) {
    return animate(node, true, done);
  },
  leave: function leave(node, done) {
    return animate(node, false, done);
  }
};
exports["default"] = animation;

