package com.auto.clicker.autoclicker.ui.activity.menu;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.auto.clicker.autoclicker.R;
import com.auto.clicker.autoclicker.databinding.ActivityMenuBinding;

public class MenuActivity extends AppCompatActivity {
    private ActivityMenuBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivityMenuBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        EdgeToEdge.enable(this);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        initData();
        initEvent();
    }

    private void initData() {
        setupItem(R.id.scripts, R.drawable.scripts, "Scripts", "Your Saved Scripts");
        setupItem(R.id.trouble, R.drawable.trouble, "Troubleshooting", "Repair your app");
        setupItem(R.id.battery, R.drawable.battery, "Battery Limit Free", "Background battery usage");
        setupItem(R.id.question, R.drawable.menu_question, "How To Use?", "How to use can use app controller");
        setupItem(R.id.share, R.drawable.share, "Share APP", "WIth you Friends");
        setupItem(R.id.feedback, R.drawable.feedback, "Feedback", "Enjoy our app?");
        setupItem(R.id.privacy, R.drawable.privacy, "Privacy policy", "Use of Cookies");
        setupItem(R.id.term, R.drawable.term, "Term & Conditions", "Rules of conduct");
    }

    private void initEvent() {
        binding.btnBack.setOnClickListener(v -> finish());

        binding.scripts.arrow.setOnClickListener(v -> {
            Intent intent = new Intent(this, ScriptsActivity.class);
            startActivity(intent);
        });

        binding.trouble.arrow.setOnClickListener(v -> {
            Intent intent = new Intent(this, TroubleshootingActivity.class);
            startActivity(intent);
        });

        binding.battery.arrow.setOnClickListener(v -> {
            Intent intent = new Intent(this, BatteryLimitFreeActivity.class);
            startActivity(intent);
        });

        binding.question.arrow.setOnClickListener(v -> {
            Intent intent = new Intent(this, HowToUseActivity.class);
            startActivity(intent);
        });
    }

    private void setupItem(int viewId, int iconRes, String title, String subtitle) {
        View item = findViewById(viewId);
        ImageView icon = item.findViewById(R.id.icon);
        TextView titleView = item.findViewById(R.id.title);
        TextView subtitleView = item.findViewById(R.id.subtitle);

        icon.setImageDrawable(ContextCompat.getDrawable(this, iconRes));
        titleView.setText(title);
        subtitleView.setText(subtitle);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        binding = null;
    }
}