import TransitionInterpolator from './transition-interpolator';
import { lerp } from '@math.gl/core';
import { flyToViewport, getFlyToDuration } from '@math.gl/web-mercator';
const LINEARLY_INTERPOLATED_PROPS = {
  bearing: 0,
  pitch: 0,
  position: [0, 0, 0]
};
const DEFAULT_OPTS = {
  speed: 1.2,
  curve: 1.414
};
export default class FlyToInterpolator extends TransitionInterpolator {
  constructor(opts = {}) {
    super({
      compare: ['longitude', 'latitude', 'zoom', 'bearing', 'pitch', 'position'],
      extract: ['width', 'height', 'longitude', 'latitude', 'zoom', 'bearing', 'pitch', 'position'],
      required: ['width', 'height', 'latitude', 'longitude', 'zoom']
    });
    this.opts = void 0;
    this.opts = { ...DEFAULT_OPTS,
      ...opts
    };
  }

  interpolateProps(startProps, endProps, t) {
    const viewport = flyToViewport(startProps, endProps, t, this.opts);

    for (const key in LINEARLY_INTERPOLATED_PROPS) {
      viewport[key] = lerp(startProps[key] || LINEARLY_INTERPOLATED_PROPS[key], endProps[key] || LINEARLY_INTERPOLATED_PROPS[key], t);
    }

    return viewport;
  }

  getDuration(startProps, endProps) {
    let {
      transitionDuration
    } = endProps;

    if (transitionDuration === 'auto') {
      transitionDuration = getFlyToDuration(startProps, endProps, this.opts);
    }

    return transitionDuration;
  }

}
//# sourceMappingURL=fly-to-interpolator.js.map