'use strict';

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

function delayFunction(id, value) {
  return function() {
    schedule.init(this, id).delay = +value.apply(this, arguments);
  };
}

function delayConstant(id, value) {
  return value = +value, function() {
    schedule.init(this, id).delay = value;
  };
}

function transition_delay(value) {
  var id = this._id;

  return arguments.length
      ? this.each((typeof value === "function"
          ? delayFunction
          : delayConstant)(id, value))
      : schedule.get(this.node(), id).delay;
}

module.exports = transition_delay;
