import { Component, OnInit } from "@angular/core";
import * as dialogs from "tns-core-modules/ui/dialogs";
import { RouterExtensions } from "nativescript-angular/router";
import { TouchGestureEventData, GestureEventData } from 'tns-core-modules/ui/gestures'
import { isEnabled, enableLocationRequest, getCurrentLocation, watchLocation, distance, clearWatch, Location } from "nativescript-geolocation";

import { MyHttpPostService } from '../services/my-http-post-service''


@Component({
    selector: "home-page",
    moduleId: module.id,
    templateUrl: './home-page.component.html',
    styleUrls: ['./home-page.component.css'],
    providers: [MyHttpPostService]
})
export class HomePageComponent implements OnInit {
    returnMessage: string = "";
    myReturnJSON: Object;
    locationData: Location;
    myPicture: String;
    image: any;
    flat_earth: boolean;
    in_australia: boolean;

    constructor(private myHttpPostSerivce: MyHttpPostService,
                private routerExtensions: RouterExtensions,
    ) { }

    ngOnInit(): void {
    }

    public onTap(args: GestureEventData): void {
        this.routerExtensions.navigateByUrl("/result-page");
        /* return this.cameraService.takePicture().
        then(picture => {
            this.image = JSON.stringify(picture);
            //console.log('this is picture in json', JSON.stringify(picture));
            this.getLocation();
        }) */
    }

    /* public getLocation(): any {
        this.geoLocationService.getLocation().then(location => {
            this.locationData = location;
            //console.log('this is locationData', this.locationData);
            this.submit();
        }).catch(error => {
        });
    }

    public submit(): void {
        this.makePostRequest();
    }

    private makePostRequest(): void {
        this.myHttpPostSerivce
            .postData({ position: this.locationData, image: this.image, flat_earth: true, in_australia: true, })
            .subscribe(res => {
                //console.log('This is res', res);
                this.myReturnJSON = res;
                console.log('THis is myreturnJSON', this.myReturnJSON);
                this.routerExtensions.navigateByUrl("/result-page");
            });
    } */
}