package com.example.pap_findu;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class AddZoneActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_zone);

        ImageButton btnBack = findViewById(R.id.btnBack);
        Button btnSave = findViewById(R.id.btnSave);
        EditText editName = findViewById(R.id.editZoneName);
        EditText editAddress = findViewById(R.id.editZoneAddress);

        // Check if opened from Map with coordinates
        if (getIntent().hasExtra("lat") && getIntent().hasExtra("lng")) {
            double lat = getIntent().getDoubleExtra("lat", 0);
            double lng = getIntent().getDoubleExtra("lng", 0);
            editAddress.setText(String.format(java.util.Locale.getDefault(), "Lat: %.5f, Lng: %.5f", lat, lng));
        }

        btnBack.setOnClickListener(v -> finish());

        btnSave.setOnClickListener(v -> {
            String name = editName.getText().toString();
            String address = editAddress.getText().toString();

            if (name.isEmpty() || address.isEmpty()) {
                Toast.makeText(this, "Preencha todos os campos", Toast.LENGTH_SHORT).show();
                return;
            }

            // Here we would save to Firebase/Database
            Toast.makeText(this, "Zona '" + name + "' adicionada com sucesso!", Toast.LENGTH_LONG).show();
            finish();
        });
    }
}
