package com.project.ilsaenterprise.monitoring;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.Manifest;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Point;
import android.os.Bundle;
import android.util.Log;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MapStyleOptions;
import com.google.android.gms.maps.model.MarkerOptions;
import com.project.ilsaenterprise.MapActivity;
import com.project.ilsaenterprise.R;

import java.util.ArrayList;

public class LokasiMonitoring extends AppCompatActivity implements OnMapReadyCallback {
    private GoogleMap mMap;
    ArrayList<Double> coordinateLocation;
    private static final float DEFAULT_ZOOM = 16.5f;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lokasi_monitoring);
        getSupportActionBar().hide();
        coordinateLocation = (ArrayList<Double>) getIntent().getSerializableExtra("monitoringList");

//        GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
//        mMapView.getGraphicsOverlays().add(graphicsOverlay);
//
//        SimpleMarkerSymbol symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.X, Color.rgb(235, 120, 0), 25); //size 12, style of circle
//        //add a new graphic with a new point geometry
//        Point graphicPoint = mapPointCon(myList.get(0), myList.get(1));
//        Graphic graphic = new Graphic(graphicPoint, symbol);
//        graphicsOverlay.getGraphics().add(graphic);
    }

    @Override
    public void onMapReady(@NonNull GoogleMap googleMap) {
        mMap = googleMap;
        mMap.isIndoorEnabled();

        try {
            boolean success = googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(this, R.raw.new_map));
            LatLng location = new LatLng(coordinateLocation.get(0), coordinateLocation.get(1));
            moveCamera(new LatLng(coordinateLocation.get(0), coordinateLocation.get(1)), DEFAULT_ZOOM);
            googleMap.addMarker(new MarkerOptions()
                    .position(location)
                    .title("Location Report"));
            if(!success){
                return;
            }
        }catch (Resources.NotFoundException e){
            //Log.e(TAG, "Error", e);
            return;
        }
        //============
    }

    private void moveCamera(LatLng latLng, float zoom){

        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoom));
        mMap.clear();
    }

    private void initMap(){
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapView);

        assert mapFragment != null;
        mapFragment.getMapAsync(LokasiMonitoring.this);
    }

    @Override
    protected void onStart() {
        super.onStart();
        initMap();
    }
}