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

import { Component, Input, OnDestroy } from '@angular/core';
import { Subject } from 'rxjs';
import { LocationEditingBehavior } from '../location-editing.behavior';
import { LocationInteractionDirective } from '../location-interaction.directive';
import { LocationMapService } from '../map/location-map.service';

export class LocationToolbarButtonSettings {
  title: string;
  icon: string;
  badge?: string;
}

const N_DASH = '–';

export class LocationToolbarSettings {
  move: LocationToolbarButtonSettings = {
    title: 'Move',
    icon: 'Bosch-Ic-hand',
  };

  modify: LocationToolbarButtonSettings = {
    title: 'Modify',
    icon: 'Bosch-Ic-edit',
  };

  addPosition: LocationToolbarButtonSettings = {
    title: 'Add Position',
    icon: 'Bosch-Ic-location-pin',
  };

  removePosition: LocationToolbarButtonSettings = {
    title: 'Remove Position',
    icon: this.addPosition.icon,
    badge: N_DASH,
  };

  addBoundary: LocationToolbarButtonSettings = {
    title: 'Add Boundary',
    icon: 'Bosch-Ic-shape-rectangle',
  };

  removeBoundary: LocationToolbarButtonSettings = {
    title: 'Remove Boundary',
    icon: this.addBoundary.icon,
    badge: N_DASH,
  };
}

@Component({
  selector: 'bci-location-toolbar',
  templateUrl: './location-toolbar.component.html',
  styleUrls: ['./location-toolbar.component.scss'],
})
export class LocationToolbarComponent implements OnDestroy {
  @Input() settings: LocationToolbarSettings = new LocationToolbarSettings();

  protected ngUnsubscribe = new Subject<void>();

  get canSetBoundary(): boolean {
    const location = this.locationMapService.locationBeingEdited;
    return this.behavior.canSetBoundary(location);
  }

  get canRemoveBoundary(): boolean {
    const location = this.locationMapService.locationBeingEdited;
    return this.behavior.canRemoveBoundary(location);
  }

  get canSetPosition(): boolean {
    const location = this.locationMapService.locationBeingEdited;
    return this.behavior.canSetPosition(location);
  }

  get canRemovePosition(): boolean {
    const location = this.locationMapService.locationBeingEdited;
    return this.behavior.canRemovePosition(location);
  }

  constructor(
    public locationMapService: LocationMapService,
    public locationInteraction: LocationInteractionDirective,
    protected behavior: LocationEditingBehavior
  ) {}

  ngOnDestroy(): void {
    this.ngUnsubscribe.next();
    this.ngUnsubscribe.complete();
  }
}
