package com.example.defenseapplication.liveVideo

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.defenseapplication.R
import com.example.defenseapplication.databinding.UserDetailsActivityBinding
import com.example.defenseapplication.view.CustomDialogFragmentText
import com.gyf.immersionbar.ImmersionBar

//用户详情页面
class UserDetailsActivity : AppCompatActivity() {
    private lateinit var binding: UserDetailsActivityBinding

    private lateinit var userName: String
    private lateinit var phone: String
    private lateinit var idCard: String
    private lateinit var time: String

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = UserDetailsActivityBinding.inflate(layoutInflater)
        setContentView(binding.root)

        ImmersionBar.with(this)
            .statusBarDarkFont(true)
            .titleBar(binding.topBar)
            .init()

        initData()
        initView()
        initListener()
    }

    private fun initData() {
        userName = intent.getStringExtra("name") ?: ""
        phone = intent.getStringExtra("phone") ?: ""
        idCard = intent.getStringExtra("idCard") ?: ""
        time = intent.getStringExtra("time") ?: ""
    }

    private fun initView() {
        binding.tvContactName.text = userName
        binding.tvPhone.text = phone
        binding.tvIdCard.text = idCard
        binding.tvMacAddress.text = "AA:BB:CC:DD:EE:FF"
    }

    private fun initListener() {
        binding.ivBack.setOnClickListener {
            finish()
        }

        binding.swUserStatus.setOnCheckedChangeListener { _, isChecked ->
            when (isChecked) {
                true -> {
                    // 打开开关业务逻辑
                }
                false -> {
                    // 关闭开关业务逻辑
                }
            }
        }

        binding.btnDelete.setOnClickListener {
            showDeleteDialog()
        }
    }


    private fun showDeleteDialog() {
        val dialog = CustomDialogFragmentText()
        dialog.setTitle(getString(R.string.tip))
        dialog.setMessage(getString(R.string.confirm_delete_user))
        dialog.setShowInput(false)
        dialog.setPositiveText(getString(R.string.confirm))
        dialog.setNegativeText(getString(R.string.cancel))
        dialog.setOnConfirmListener {
            finish()
        //   if(){
        //       ToastUtils.showSuccess(this, getString(R.string.wifi_connection_success)
        //   }else{
        //       ToastUtils.showError(this, getString(R.string.wifi_connection_failed))
        //   }
        }
        dialog.show(supportFragmentManager, "DeleteUserDialog")
    }
}