package com.develop.setting.init.ui

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route

import com.develop.food.base.router.Screens
import com.develop.food.base.ui.BaseActivity
import com.develop.food.base.utils.QRCodeUtils
import com.develop.food.base.utils.ThreadUtils
import com.develop.food.base.utils.TuyaUtils
import com.develop.food.base.utils.updateText
import com.develop.setting.R
import com.develop.setting.databinding.ActivityTuyaBinding
import com.tuya.smartai.iot_sdk.*

import org.greenrobot.eventbus.Subscribe


@Route(path = Screens.Setting.TUYA)
class TuyaActivity : BaseActivity<ActivityTuyaBinding>() {

    private val TAG = "TUYA"

    var mPid: String? = "dquk8axtyy72c1ap"
    var mUid: String? = "uuid50e9e0c707553116"
    var mAk: String? = "MJhcxmQ6LeZDj1tNu6F5kqK5aQJfpdOb"

    var ioTSDKManager: IoTSDKManager? = null


    override fun createViewBinding(inflater: LayoutInflater):ActivityTuyaBinding {
        return ActivityTuyaBinding.inflate(layoutInflater)
    }

    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)
        binding.topBar.setTopBarTitle(getString(R.string.tuya))
        binding.topBar.listenBackClick {
            finish()
        }


        if(TuyaUtils.qrcodeUrl != "" && !TuyaUtils.init){
            ThreadUtils.runOnMainThread {
                val bitmap = QRCodeUtils.createQRCodeBitmap(TuyaUtils.qrcodeUrl, 500, 500)
                binding.tuyaQrcode.setImageBitmap(bitmap)
                binding.tuyaQrcode.visibility = View.VISIBLE
            }
        }else{
                binding.cancelWrapper.visibility = View.VISIBLE
                binding.cancelBtn.setOnClickListener{
                    TuyaUtils.cancelBind()
                }
        }


    }


    @Subscribe
    fun onTuyaStateChange(event:TuyaUtils){
        println("adasdasd")
    }




}