package com.example.watch.ui.activity

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.example.watch.R

class SettingActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //        白色状态栏
        setStatusBarColor()
        setContentView(com.example.watch.R.layout.activity_setting)

//        切换tab
        turnTabPage()
//        获取基础数据
        getBaseData()
//        获取新版本
        getLastVersion()

//        推出登录
        logout()

    }

    private fun logout() {
        findViewById<Button>(R.id.logout).setOnClickListener {
            Toast.makeText(this, "当前账号已退出", Toast.LENGTH_LONG).show()
            startActivity(Intent(this, LoginActivity::class.java))
        }

    }

    private fun getLastVersion() {
        findViewById<LinearLayout>(R.id.curent_version).setOnClickListener {
            Toast.makeText(this, "当前版本已是最新版本", Toast.LENGTH_LONG).show()
        }
    }

    private fun getBaseData() {
        findViewById<TextView>(R.id.name).text = BaseData().name
        findViewById<TextView>(R.id.phone).text = BaseData().phone
        var sex = if (BaseData().sex == 1) "男" else "女"
        val baseInfo =
            BaseData().age.toString() + "岁" + " ｜ " + sex + " ｜ " + BaseData().heigh + "cm ｜  " + BaseData().weight + "kg"
        findViewById<TextView>(R.id.baseInfo).text = baseInfo
    }

    fun setStatusBarColor() {
        val window = window
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
        window.statusBarColor = resources.getColor(R.color.pink)
    }

    private fun turnTabPage() {
        val home_btn = findViewById<View>(R.id.navigation_home)
        home_btn.setOnClickListener {
            startActivity(Intent(this, MainActivity::class.java))
        }
        val setting_btn = findViewById<View>(R.id.navigation_setting)
        setting_btn.setOnClickListener {
            val SettingActivityIntent = Intent(this, SettingActivity::class.java)
            startActivity(SettingActivityIntent)
        }
    }
}