package org.tensorflow.lite.examples.poseestimation

import android.content.Intent
import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.cardview.widget.CardView
import com.google.android.material.button.MaterialButton

class GenderSelectionActivity : AppCompatActivity() {
    private lateinit var maleButton: CardView
    private lateinit var femaleButton: CardView
    private lateinit var maleText: TextView
    private lateinit var femaleText: TextView
    private lateinit var nextButton: MaterialButton
    private var selectedGender: String? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_gender_selection)

        maleButton = findViewById(R.id.maleButton)
        femaleButton = findViewById(R.id.femaleButton)
        maleText = findViewById(R.id.maleText)
        femaleText = findViewById(R.id.femaleText)
        nextButton = findViewById(R.id.nextButton)

        setupClickListeners()
    }

    private fun setupClickListeners() {
        maleButton.setOnClickListener {
            updateSelection("male")
        }

        femaleButton.setOnClickListener {
            updateSelection("female")
        }

        nextButton.setOnClickListener {
            // 跳转到年龄选择页面，并传递性别信息
            val intent = Intent(this, AgeSelectionActivity::class.java)
            intent.putExtra("selected_gender", selectedGender)
            startActivity(intent)
        }
    }

    private fun updateSelection(gender: String) {
        selectedGender = gender
        
        // 更新UI状态
        when (gender) {
            "male" -> {
                maleButton.setCardBackgroundColor(getColor(android.R.color.holo_purple))
                femaleButton.setCardBackgroundColor(getColor(android.R.color.darker_gray))
                maleText.setTextColor(getColor(android.R.color.holo_purple))
                femaleText.setTextColor(getColor(android.R.color.white))
            }
            "female" -> {
                femaleButton.setCardBackgroundColor(getColor(android.R.color.holo_purple))
                maleButton.setCardBackgroundColor(getColor(android.R.color.darker_gray))
                femaleText.setTextColor(getColor(android.R.color.holo_purple))
                maleText.setTextColor(getColor(android.R.color.white))
            }
        }
        
        // 启用Next按钮
        nextButton.isEnabled = true
    }
} 