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

import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { CustomFormComponent } from '@bci-web-core/pinboard';

@Component({
  selector: 'bci-metric-settings',
  templateUrl: './metric-settings.component.html',
  // ,
  // styleUrls: ['./metric-settings.component.scss']
})
export class MetricSettingsComponent implements OnInit, CustomFormComponent {
  baseUrls: string[] = ['/INL_CY/rest/v1/metrics', '/INL_RS/rest/v1/metrics', '/INL_TS/rest/v1/metrics'];
  selectedBaseUrl: string = this.baseUrls[0];

  private _formGroup: FormGroup;

  get formGroup(): FormGroup {
    return this._formGroup;
  }

  set formGroup(frmGroup: FormGroup) {
    this._formGroup = frmGroup;
    console.log('My custom form got this formGroup:', this.formGroup);
  }

  ngOnInit() {
    const ctrl = new FormControl(this.selectedBaseUrl, Validators.required);
    this._formGroup.addControl('url', ctrl);
  }
}
