package com.brisco.meatwholesaler;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.google.android.material.card.MaterialCardView;

public class ContactActivity extends AppCompatActivity {

    private TextView textViewAddress;
    private TextView textViewWorkingHours;
    private TextView textViewPhone;
    private TextView textViewEmail;
    private Button buttonCall;
    private Button buttonEmail;
    private Button buttonDirections;
    private Button buttonWebsite;

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

        // Setup toolbar
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setTitle("Contact Us");
        }

        // Initialize views
        initializeViews();

        // Setup click listeners
        setupClickListeners();
    }

    private void initializeViews() {
        textViewAddress = findViewById(R.id.text_address);
        textViewWorkingHours = findViewById(R.id.text_working_hours);
        textViewPhone = findViewById(R.id.text_phone);
        textViewEmail = findViewById(R.id.text_email);
        buttonCall = findViewById(R.id.btn_call);
        buttonEmail = findViewById(R.id.btn_email);
        buttonDirections = findViewById(R.id.btn_directions);
        buttonWebsite = findViewById(R.id.btn_website);
    }

    private void setupClickListeners() {
        buttonCall.setOnClickListener(v -> {
            Intent intent = new Intent(Intent.ACTION_DIAL);
            intent.setData(Uri.parse("tel:0111234567")); // Replace with actual phone number
            startActivity(intent);
        });

        buttonEmail.setOnClickListener(v -> {
            Intent intent = new Intent(Intent.ACTION_SENDTO);
            intent.setData(Uri.parse("mailto:info@brisco.bizvino.co.za")); // Replace with actual email
            intent.putExtra(Intent.EXTRA_SUBJECT, "Inquiry from Brisco App");
            startActivity(intent);
        });

        buttonDirections.setOnClickListener(v -> {
            // Open Google Maps with the address
            Uri gmmIntentUri = Uri.parse("geo:0,0?q=Unit 14, Pomona Junction, Cnr Constantia Rd & Bon Cretion Rd, Pomona, Kempton Park");
            Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
            mapIntent.setPackage("com.google.android.apps.maps");
            if (mapIntent.resolveActivity(getPackageManager()) != null) {
                startActivity(mapIntent);
            }
        });

        buttonWebsite.setOnClickListener(v -> {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("https://brisco.bizvino.co.za"));
            startActivity(intent);
        });
    }

    @Override
    public boolean onSupportNavigateUp() {
        onBackPressed();
        return true;
    }
}
