package com.dahe.gldriver.ui.waybill.activity

import android.os.Bundle
import com.dahe.gldriver.R
import com.dahe.gldriver.base.AppConfig
import com.dahe.gldriver.databinding.ActivityWaybillSuccBinding
import com.dahe.mylibrary.base.BaseActivity
import com.dahe.mylibrary.utils.ActivityUtils
import com.dahe.mylibrary.utils.AppUtils
import com.dahe.mylibrary.utils.BaseUtils
import com.dahe.mylibrary.utils.ToastUtils

/**
 * @ClassName WaybillSuccActivity
 * @Author john
 * @Date 2024/1/29 16:42
 * @Description 接单 装货 卸货成功页面
 */
class WaybillSuccActivity : BaseActivity<ActivityWaybillSuccBinding>() {
    override fun initView(savedInstanceState: Bundle?) {
        setStatusBarColor(R.color.white)
        val type = intent.extras?.getInt(AppConfig.SUCCESS_TYPE)
        setTitleBar("接单成功", true)
        changeType(type)
        binding.run {
            btnLeft.setOnClickListener {
                goLeftOrRight(type,true)
            }
            btnRight.setOnClickListener {
                goLeftOrRight(type,false)
            }
        }
    }

    override fun initDate() {

    }

    /**
     * type: 0->接单成功（默认）， 1->装货成功 ， 2->卸货成功
     */
    private fun changeType(type: Int?) {
        when (type) {
            1 -> {
                setTitleBar("装货成功")
                binding.run {
                    ivSucc.layoutParams.run {
                        width = BaseUtils.dip2px(mContext, 220f)
                        height = BaseUtils.dip2px(mContext, 150f)
                        ivSucc.layoutParams = this
                        ivSucc
                    }.setBackgroundResource(R.drawable.icon_succ_load)
                    tvSucc.text = "恭喜您，装货成功"
                    btnLeft.text = "返回首页"
                    btnRight.text = "查看运单"
                }

            }

            2 -> {
                setTitleBar("卸货成功")
                binding.run {
                    ivSucc.layoutParams.run {
                        width = BaseUtils.dip2px(mContext, 220f)
                        height = BaseUtils.dip2px(mContext, 150f)
                        ivSucc.layoutParams = this
                        ivSucc
                    }.setBackgroundResource(R.drawable.icon_succ_unload)
                    tvSucc.text = "恭喜您，卸货成功"
                    btnLeft.text = "返回首页"
                    btnRight.text = "查看运单"
                }
            }
        }
    }

    /*
    *
    * */
    private fun goLeftOrRight(type: Int?, isLeft: Boolean) {
        if (isLeft){
            when(type){
                0->ActivityUtils.startActivity(mContext, WaybillLoadActivity::class.java)
                1,2->ActivityUtils.startHomeActivity(mContext)
            }
        }else{
            when(type){
                0->ActivityUtils.startActivity(mContext, WaybillUpPicActivity::class.java,Bundle().apply { putInt(AppConfig.SUCCESS_TYPE,1) })
                1->ActivityUtils.startActivity(mContext, WaybillUnlLoadActivity::class.java)
                2->ActivityUtils.startActivity(mContext, WaybillDetailActivity::class.java)
            }
        }
    }

}