package org.tensorflow.lite.examples.poseestimation

import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.textfield.TextInputEditText
import android.widget.Button
import android.widget.TextView
import android.widget.EditText

class LoginActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_login)

        // 获取从上一个页面传递的数据
        val selectedGender = intent.getStringExtra("selected_gender")
        val selectedAge = intent.getIntExtra("selected_age", 0)
        val selectedWeight = intent.getIntExtra("selected_weight", 0)
        val selectedHeight = intent.getIntExtra("selected_height", 0)

        // 绑定控件
        val emailEdit = findViewById<EditText>(R.id.editEmail)
        val passwordEdit = findViewById<EditText>(R.id.editPassword)
        val loginBtn = findViewById<Button>(R.id.btnLogin)
        val forgotPassword = findViewById<TextView>(R.id.forgotPassword)
        val signupTab = findViewById<TextView>(R.id.tabSignup)

        // 登录按钮点击事件
        loginBtn.setOnClickListener {
            val email = emailEdit.text.toString().trim()
            val password = passwordEdit.text.toString().trim()

            // 表单验证
            if (email.isEmpty()) {
                emailEdit.error = "请输入用户名"
                return@setOnClickListener
            }
            if (password.isEmpty()) {
                passwordEdit.error = "请输入密码"
                return@setOnClickListener
            }

            // TODO: 这里添加实际的登录验证逻辑
            // 目前仅做演示，直接跳转到主页面
            val intent = Intent(this, MainActivity::class.java)
            intent.putExtra("selected_gender", selectedGender)
            intent.putExtra("selected_age", selectedAge)
            intent.putExtra("selected_weight", selectedWeight)
            intent.putExtra("selected_height", selectedHeight)
            startActivity(intent)
            finish()
        }

        // 忘记密码点击事件
        forgotPassword.setOnClickListener {
            Toast.makeText(this, "忘记密码功能开发中", Toast.LENGTH_SHORT).show()
        }

        // Sign up Tab点击事件
        signupTab.setOnClickListener {
            startActivity(Intent(this, SignupActivity::class.java))
        }
    }
}
