'use strict';

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

var schedule = require('./transition/schedule.js');

function interrupt(node, name) {
  var schedules = node.__transition,
      schedule$1,
      active,
      empty = true,
      i;

  if (!schedules) return;

  name = name == null ? null : name + "";

  for (i in schedules) {
    if ((schedule$1 = schedules[i]).name !== name) { empty = false; continue; }
    active = schedule$1.state > schedule.STARTING && schedule$1.state < schedule.ENDING;
    schedule$1.state = schedule.ENDED;
    schedule$1.timer.stop();
    schedule$1.on.call(active ? "interrupt" : "cancel", node, node.__data__, schedule$1.index, schedule$1.group);
    delete schedules[i];
  }

  if (empty) delete node.__transition;
}

exports.default = interrupt;
