'use strict';

var errors = require('../../errors.js');
var noop = require('../../noop.js');
var anticipate = require('../anticipate.js');
var back = require('../back.js');
var circ = require('../circ.js');
var cubicBezier = require('../cubic-bezier.js');
var ease = require('../ease.js');
var isBezierDefinition = require('./is-bezier-definition.js');

const easingLookup = {
    linear: noop.noop,
    easeIn: ease.easeIn,
    easeInOut: ease.easeInOut,
    easeOut: ease.easeOut,
    circIn: circ.circIn,
    circInOut: circ.circInOut,
    circOut: circ.circOut,
    backIn: back.backIn,
    backInOut: back.backInOut,
    backOut: back.backOut,
    anticipate: anticipate.anticipate,
};
const isValidEasing = (easing) => {
    return typeof easing === "string";
};
const easingDefinitionToFunction = (definition) => {
    if (isBezierDefinition.isBezierDefinition(definition)) {
        // If cubic bezier definition, create bezier curve
        errors.invariant(definition.length === 4, `Cubic bezier arrays must contain four numerical values.`, "cubic-bezier-length");
        const [x1, y1, x2, y2] = definition;
        return cubicBezier.cubicBezier(x1, y1, x2, y2);
    }
    else if (isValidEasing(definition)) {
        // Else lookup from table
        errors.invariant(easingLookup[definition] !== undefined, `Invalid easing type '${definition}'`, "invalid-easing-type");
        return easingLookup[definition];
    }
    return definition;
};

exports.easingDefinitionToFunction = easingDefinitionToFunction;
