import { Component, OnInit, Input,
    ChangeDetectorRef, ChangeDetectionStrategy } from '@angular/core'

import { MatSnackBar } from '@angular/material/snack-bar'

import { AdminManageDataService, RawSurveyPoint } from '../data.service'
import { CategoryRead } from '../../../openapi'


@Component({
    selector: 'gisaf-admin-raw-survey-point',
    templateUrl: './raw-survey-point.component.html',
    styleUrls: ['./raw-survey-point.component.css'],
    changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RawSurveyPointComponent {
    @Input() rawSurveyPoint: RawSurveyPoint
    @Input() newStatus: string
    @Input() category: string
    @Input() canDelete: boolean

    constructor(
        private adminManageDataService: AdminManageDataService,
        private cdr: ChangeDetectorRef,
        private snackBar: MatSnackBar,
    ) {}

    changeStatus(evt) {
        this.adminManageDataService.changeStatus(this.rawSurveyPoint, this.newStatus).subscribe(
            (res: Object) => {
                this.snackBar.open(res['message'], 'OK')
            }
        )
    }

    delete(evt) {
        this.adminManageDataService.delete(this.rawSurveyPoint).subscribe(
            (res: Object) => {
                this.snackBar.open(res['message'], 'OK')
            }
        )
    }

    reconcile(evt) {
        this.adminManageDataService.reconcile(this.rawSurveyPoint, this.category).subscribe(
            (res: Object) => {
                this.snackBar.open(res['message'], 'OK')
            }
        )
    }
}