import Months from "./Months";

// 上下拉动
function slideY(op, _ref) {
  var duration = _ref.duration,
    weekStart = _ref.weekStart,
    drawDate = _ref.drawDate,
    cellHeight = _ref.cellHeight,
    bodyHeight = _ref.bodyHeight,
    body = _ref.body,
    bodyY = _ref.bodyY;
  // 添加动画
  body.style.transitionDuration = duration + 'ms';
  var height = 0;
  var translateY = 0;
  var drawDateRowIndex = Months.getDateRowIndex(drawDate, weekStart);

  // 样式标记展开和收缩, 暂时无意义
  if (op) {
    body.parentNode.classList.remove('expand');
    body.parentNode.classList.remove('collapse');
    body.parentNode.classList.add(op);
  }

  // 展开
  if (op === 'expand') {
    height = bodyHeight;
    translateY = 0;
    bodyY.setAttribute('data-translateY', translateY);
  }
  // 收缩
  else if (op === 'collapse') {
    height = cellHeight;
    translateY = -drawDateRowIndex * cellHeight;
    bodyY.setAttribute('data-translateY', translateY);
  }
  // 维持现状
  else {
    height = body.getAttribute('data-height');
    translateY = bodyY.getAttribute('data-translateY');
  }
  body.style.height = height + 'px';
  bodyY.style.transform = 'translateY(' + translateY + 'px)';

  // 动画执行结束后刷新日历
  setTimeout(function () {
    // 清除动画
    body.style.transitionDuration = '0ms';

    // 重置拖动前高度
    body.removeAttribute('data-height');
  }, duration);
}
export default slideY;