package com.abbidot.tracker.deprecated.adapter

import android.content.Context
import android.view.View
import androidx.core.content.ContextCompat
import com.abbidot.baselibrary.list.BaseRecyclerAdapter
import com.abbidot.baselibrary.list.RecyclerViewHolder
import com.abbidot.baselibrary.util.Utils
import com.abbidot.tracker.R
import com.abbidot.tracker.bean.SetMealBean
import com.abbidot.tracker.constant.ConstantInt
import com.abbidot.tracker.util.ViewUtil

/**
 *Created  by .yzq on 2022/7/23/023.
 * @link
 * @description:
 */
class RechargeAmountCNAdapter(ctx: Context, list: MutableList<SetMealBean>?) :
    BaseRecyclerAdapter<SetMealBean>(ctx, list) {

    private var mSelectIndex = -1

    override fun getEmptyLayoutId(viewType: Int) = 0

    override fun getItemLayoutId(viewType: Int) = R.layout.item_recharge_amount_cn

    override fun bindData(holder: RecyclerViewHolder?, position: Int, item: SetMealBean) {
        val view = holder!!.itemView
        if (position == mSelectIndex) {
            view.background = ContextCompat.getDrawable(mContext, R.drawable.shape10_yellow_bg)
        } else {
            view.background = ContextCompat.getDrawable(mContext, R.drawable.shape12_gray_white_bg)
        }
        ViewUtil.instance.setShapeRadius(view, 6)

        if (item.hotType == ConstantInt.Type1) {
            holder.getImageView(R.id.recharge_amount_cn_normal_hot_image).visibility = View.VISIBLE
        } else {
            holder.getImageView(R.id.recharge_amount_cn_normal_hot_image).visibility = View.GONE
        }
        val period = item.period
        val perMonth = if (period < 2) {
            String.format(mContext.getString(R.string.pet_managet_age), period)
        } else {
            String.format(mContext.getString(R.string.pet_managet_age), period)
        }
        holder.setText(R.id.recharge_amount_cn_two_time, perMonth)
        holder.setText(R.id.recharge_amount_cn_two_money, item.accountFee.toString())

        val averageMonth = Utils.formatDecimal(item.accountFee / (12 * period), 2)
        val monthString = String.format(mContext.getString(R.string.txt_perMonth), averageMonth)
        holder.setText(R.id.recharge_amount_cn_two_description, monthString)
    }

    fun setSelectIndex(index: Int) {
        mSelectIndex = index
        notifyDataSetChanged()
    }

    fun getSelectIndex() = mSelectIndex
}