import { Component, Injectable,ViewChild,AfterViewInit} from '@angular/core';
import { Feature } from 'ol';
import { Geometry } from 'ol/geom';
import { Store } from '@ngrx/store';
import * as mapReducers from '../../reducers/map.reducer';
import { commonReducers,ItemTypeService,AppConfig } from '@farmmaps/common';
import { AbstractFeatureListFeatureComponent } from '../feature-list-feature/feature-list-feature.component';
import { ForItemType } from '../for-item/for-itemtype.decorator';
import {getArea} from 'ol/sphere';



@ForItemType("vnd.farmmaps.itemtype.cropfield")
@Injectable()
@Component({
  selector: 'fm-map-feature-list-feature-cropfield',
  templateUrl: './feature-list-feature-cropfield.component.html',
  styleUrls: ['./feature-list-feature-cropfield.component.scss']
})
export class FeatureListFeatureCropfieldComponent extends AbstractFeatureListFeatureComponent {


  constructor(store: Store<mapReducers.State | commonReducers.State>, itemTypeService: ItemTypeService,config:AppConfig) {
    super(store, itemTypeService,config);
  }

  areaInHa(feature:Feature<Geometry>):number {
    if(!feature) return 0;
    // get area from faeture if 0 calculate from polygon
    const a = feature.get('area');
    if(a) return a;
    return  getArea(feature.getGeometry(),{projection:"EPSG:3857"}) / 10000;
  }
}
