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

export class MapEditorPage {
  navigateTo() {
    cy.visit('/maps/editor');
    return cy.get('bci-open-layers-map', { timeout: 10000 }).should('be.visible');
  }

  enterPolylineMode() {
    return cy.get('.bosch-ic-share').click();
  }

  enterPolygonMode() {
    return cy.get('.bosch-ic-material').click();
  }

  drawPoly(coordinates: number[][]) {
    coordinates.forEach((xy) => {
      this.getCanvas().click(xy[0], xy[1]);
    });

    const lastXY = coordinates.reverse()[0];
    this.getCanvas().click(lastXY[0], lastXY[1]);
  }

  getCanvas() {
    return cy.get('canvas');
  }

  getLastChangedFeature() {
    return cy.get('*[data-e2e-last-changed-feature]');
  }

  openLastChangedFeatureHeader() {
    return cy.get('[data-test="last-changed-panel-header"]').click({force: true});
  }

  getVectorLayerExport() {
    return cy.get('*[data-e2e-vector-layer-geojson]');
  }
}
