'use strict';

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

function durationFunction(id, value) {
  return function() {
    schedule.set(this, id).duration = +value.apply(this, arguments);
  };
}

function durationConstant(id, value) {
  return value = +value, function() {
    schedule.set(this, id).duration = value;
  };
}

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

  return arguments.length
      ? this.each((typeof value === "function"
          ? durationFunction
          : durationConstant)(id, value))
      : schedule.get(this.node(), id).duration;
}

module.exports = transition_duration;
