package com.stand.standapp

import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity

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

        // 左上角退出
        findViewById<ImageView>(R.id.btn_close).setOnClickListener {
            finish()
        }

        // PTT 测试
        findViewById<LinearLayout>(R.id.item_ptt).setOnClickListener {
            startActivity(Intent(this, com.example.kingway.ptt.pttActivity::class.java))
        }

        // 打印测试
        findViewById<LinearLayout>(R.id.item_printer).setOnClickListener {
            startActivity(Intent(this, com.stand.standapp.printer.PrintTestActivity::class.java))
        }

        // 崩溃模拟
        findViewById<LinearLayout>(R.id.item_crash_test).setOnClickListener {
            androidx.appcompat.app.AlertDialog.Builder(this)
                .setTitle("确认崩溃测试？")
                .setMessage("应用将立即崩溃并尝试记录日志，确定继续吗？")
                .setPositiveButton("确定") { _, _ ->
                    throw RuntimeException("这是一次开发者手动触发的模拟崩溃测试")
                }
                .setNegativeButton("取消", null)
                .show()
        }

        // 加载调试信息
        loadDebugInfo()
    }

    private fun loadDebugInfo() {
        val tvInfo = findViewById<TextView>(R.id.tv_debug_info)
        val info = StringBuilder()
        info.append("设备型号: ${Build.MODEL}\n")
        info.append("系统版本: Android ${Build.VERSION.RELEASE} (SDK ${Build.VERSION.SDK_INT})\n")
        info.append("架构(ABI): ${Build.SUPPORTED_ABIS.joinToString(", ")}\n")
        info.append("运行模式: ${if (android.os.Process.is64Bit()) "64位" else "32位兼容模式"}\n")
        info.append("服务器地址: ${AppConfig.getServerUrl(this)}\n")
        info.append("串口路径: ${AppConfig.getSerialPort(this)}")
        
        tvInfo.text = info.toString()
    }
}
