package com.dahe.gldriver.ui.mine.activity

import android.os.Bundle
import android.view.View
import com.dahe.gldriver.databinding.ActivityCarDetailBinding
import com.dahe.gldriver.databinding.ActivityDriverTeamDetailBinding
import com.dahe.gldriver.net.BaseObserver
import com.dahe.gldriver.net.DataManager
import com.dahe.gldriver.net.RxHttpCallBack
import com.dahe.gldriver.utils.SPUtils
import com.dahe.glex.bean.UserDetail
import com.dahe.mylibrary.base.BaseActivity
import com.dahe.mylibrary.net.CommonResponseBean
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.schedulers.Schedulers

/**
 * @ClassName CarDetailActivity
 * @Author john
 * @Date 2024/3/21 11:24
 * @Description TODO
 */
class CarDetailActivity : BaseActivity<ActivityCarDetailBinding>() {

    var doneInfoCount = 0
    override fun initView(savedInstanceState: Bundle?) {
        setStatusHeightParams(binding.rlTop)
        setTitleBar("车辆详情", true)
    }

    override fun initDate() {
        DataManager.getInstance().getUserDetail()
            .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
            .subscribe(BaseObserver(mContext, object : RxHttpCallBack<UserDetail>() {
                override fun onSuccess(t: CommonResponseBean<UserDetail>) {
                    super.onSuccess(t)
                    initViewByData(t.data)
                }
            }))
    }

    private fun initViewByData(data: UserDetail) {
//        userDetail = data
        binding.run {
            val userInfo = SPUtils.instance.getUserInfo(mContext)
            var missInfo = ""

            if (data.idcardNo.isNullOrEmpty()) {
                tvInfo.text = "证件缺失将无法进行接单"
                missInfo.plus("行驶证、")
            } else {
                doneInfoCount++
                tvInfo.text = """${data.idcardName} ${data.idcardNo}"""
            }
            if (data.licenseNo.isNullOrEmpty()) {
                tvDriverInfo.text = "证件缺失将无法进行接单"
                missInfo.plus("挂车行驶证、")
            } else {
                doneInfoCount++
                tvDriverInfo.text = """${data.licenseName} ${data.licenseNo}"""
            }
            if (data.qualificationCertificateNo.isNullOrEmpty()) {
                tvQualiInfo.text = "证件缺失将无法进行接单"
                missInfo.plus("道路运输许可证、")
            } else {
                doneInfoCount++
                tvQualiInfo.text = """${data.qualificationCertificateNo}"""
            }


            btnNext.text = if (doneInfoCount == 3) "已完成" else "继续认证"
            tvContent.text = if (missInfo.isNullOrEmpty()) "认证成功,请接单把!!!" else missInfo


            llId.visibility = if (data.idcardNo.isNullOrEmpty()) View.GONE else View.VISIBLE
            btnId.visibility = if (data.idcardNo.isNullOrEmpty()) View.VISIBLE else View.GONE

            llDriver.visibility = if (data.licenseNo.isNullOrEmpty()) View.GONE else View.VISIBLE
            btnDriver.visibility = if (data.licenseNo.isNullOrEmpty()) View.VISIBLE else View.GONE
            llQua.visibility =
                if (data.qualificationCertificateNo.isNullOrEmpty()) View.GONE else View.VISIBLE
            btnQua.visibility =
                if (data.qualificationCertificateNo.isNullOrEmpty()) View.VISIBLE else View.GONE

            circleBarView2.progress = doneInfoCount * 100 / 3

        }
    }
}