/*
 * Copyright (C) 2018 Robert Bosch GmbH Copyright (C) 2018 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved.
 */

import Collection from 'ol/Collection';
import Feature from 'ol/Feature';
import Translate, { TranslateEvent } from 'ol/interaction/Translate';
import { Observable, Subject } from 'rxjs';
import { InteractionMode } from '../interaction-mode';

export class TranslationInteractionMode extends InteractionMode {
  readonly translate = new Translate({
    features: this.selectedFeatures,
  });
  private _translation = new Subject<TranslateEvent>();
  readonly translated: Observable<TranslateEvent> = this._translation.asObservable();

  constructor(private selectedFeatures?: Collection<Feature>) {
    super();
  }

  activate() {
    this.activateInteraction(this.translate);
    this.registerListener(this.translate.on('translateend', (event: TranslateEvent) => this._translation.next(event)));
    super.activate();
  }

  deactivate() {
    super.deactivate();
  }
}
