package com.abbidot.tracker.ui.activity.pet

import android.view.View
import com.abbidot.tracker.R
import com.abbidot.tracker.base.BaseActivity
import com.abbidot.tracker.bean.DataBean
import com.abbidot.tracker.constant.ConstantInt
import com.abbidot.tracker.constant.ConstantString
import com.abbidot.tracker.databinding.ActivityBadgeDetailBinding
import com.abbidot.tracker.util.Util

class BadgeDetailActivity :
    BaseActivity<ActivityBadgeDetailBinding>(ActivityBadgeDetailBinding::inflate) {

    private var mDataBean: DataBean? = null

    override fun getTopBar() = mViewBinding.petBadgesDetailTopBar.titleTopBar

    override fun initData() {
        super.initData()
        setTopBarTitle(R.string.pet_manage_detail_title2)

        intent.extras?.apply {
            mDataBean =
                Util.getParcelableAdaptive(intent, ConstantString.PetLabels, DataBean::class.java)
        }

        mViewBinding.apply {
            root.setBackgroundResource(R.color.white)
            mDataBean?.let {
                setTopBarTitle(it.name)
                tvPetBadgesDetailDec.text = it.unit
                ivPetBadgesDetailImage.setImageResource(it.imageId)

                if (it.state == ConstantInt.Open) {
                    ivPetBadgesDetailImage.setBackgroundResource(R.drawable.icon_badges_unlock_bg_svg)
                    tvPetBadgesDetailState.setText(R.string.txt_congratulations)
                    tvPetBadgesDetailUnlockTime.text = it.value
                    tvPetBadgesDetailUnlockTime.visibility = View.VISIBLE
                } else {
                    ivPetBadgesDetailImage.setBackgroundResource(0)
                    tvPetBadgesDetailState.setText(R.string.txt_how_to_get)
                    tvPetBadgesDetailUnlockTime.visibility = View.INVISIBLE
                }
            }

            setOnClickListenerViews(btnPetBadgesDetailOk)
        }
    }

    override fun onClick(v: View?) {
        mViewBinding.apply {
            when (v!!) {
                btnPetBadgesDetailOk -> finish()
            }
        }
    }
}