import { equals } from '@math.gl/core';
import assert from '../utils/assert';
export default class TransitionInterpolator {
  constructor(opts) {
    this._propsToCompare = void 0;
    this._propsToExtract = void 0;
    this._requiredProps = void 0;
    const {
      compare,
      extract,
      required
    } = opts;
    this._propsToCompare = compare;
    this._propsToExtract = extract || compare;
    this._requiredProps = required;
  }

  arePropsEqual(currentProps, nextProps) {
    for (const key of this._propsToCompare) {
      if (!(key in currentProps) || !(key in nextProps) || !equals(currentProps[key], nextProps[key])) {
        return false;
      }
    }

    return true;
  }

  initializeProps(startProps, endProps) {
    const startViewStateProps = {};
    const endViewStateProps = {};

    for (const key of this._propsToExtract) {
      if (key in startProps || key in endProps) {
        startViewStateProps[key] = startProps[key];
        endViewStateProps[key] = endProps[key];
      }
    }

    this._checkRequiredProps(startViewStateProps);

    this._checkRequiredProps(endViewStateProps);

    return {
      start: startViewStateProps,
      end: endViewStateProps
    };
  }

  getDuration(startProps, endProps) {
    return endProps.transitionDuration;
  }

  _checkRequiredProps(props) {
    if (!this._requiredProps) {
      return;
    }

    this._requiredProps.forEach(propName => {
      const value = props[propName];
      assert(Number.isFinite(value) || Array.isArray(value), `${propName} is required for transition`);
    });
  }

}
//# sourceMappingURL=transition-interpolator.js.map