package com.helldivers.app;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private SoundManager soundManager;
    private Button btnQrInstagram;
    private Button btnMinijuego;
    private ImageButton btnUp, btnDown, btnLeft, btnRight;

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

        try {
            soundManager = new SoundManager(this);
        } catch (Exception e) {
            soundManager = null;
        }

        btnQrInstagram = findViewById(R.id.btn_qr_instagram);
        btnMinijuego = findViewById(R.id.btn_minijuego);
        btnUp = findViewById(R.id.btn_up);
        btnDown = findViewById(R.id.btn_down);
        btnLeft = findViewById(R.id.btn_left);
        btnRight = findViewById(R.id.btn_right);

        if (btnQrInstagram != null) {
            btnQrInstagram.setOnClickListener(v -> {
                startActivity(new Intent(this, ActivityQR.class));
            });
        }

        if (btnMinijuego != null) {
            btnMinijuego.setOnClickListener(v -> {
                startActivity(new Intent(this, ActivityGame.class));
            });
        }

        View.OnClickListener arrowSoundListener = v -> {
            if (soundManager != null) {
                try { soundManager.playButtonClick(); } catch (Exception e) {}
            }
        };

        if (btnUp != null) btnUp.setOnClickListener(arrowSoundListener);
        if (btnDown != null) btnDown.setOnClickListener(arrowSoundListener);
        if (btnLeft != null) btnLeft.setOnClickListener(arrowSoundListener);
        if (btnRight != null) btnRight.setOnClickListener(arrowSoundListener);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (soundManager != null) soundManager.resume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (soundManager != null) soundManager.pause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (soundManager != null) soundManager.release();
    }
}