package com.abbidot.tracker.adapter

import android.content.Context
import android.view.View
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.PackageBean
import com.abbidot.tracker.constant.ConstantInt
import com.abbidot.tracker.constant.ConstantString

/**
 *Created  by .yzq on 2024/8/6/006.
 * @link
 * @description:
 */
class ChoosePlanAdapter(
    ctx: Context, list: MutableList<PackageBean>?
) : BaseRecyclerAdapter<PackageBean>(ctx, list) {
    override fun getEmptyLayoutId(viewType: Int) = 0

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

    override fun bindData(holder: RecyclerViewHolder?, position: Int, item: PackageBean) {
        holder?.apply {
            getView(R.id.rl_choose_plan_shade_item).let {
                if (item.selected) it.setBackgroundResource(R.drawable.shape20_yellow_border_cyan_bg)
                else it.setBackgroundResource(0)
            }

            setText(R.id.tv_choose_plan_item_name, item.planName)

//            val price = if (item.discountedPrice > 0) item.discountedPrice else item.planPrice
            getTextView(R.id.tv_choose_plan_item_money).apply {
                text = String.format(
                    mContext.getString(R.string.txt_money_unit),
                    Utils.formatDecimal(item.planPrice / item.planTimeMonthsCount, 2)
                )
            }

            getTextView(R.id.tv_choose_plan_item_plan_money).text = String.format(
                mContext.getString(R.string.txt_money_unit), Utils.formatDecimal(item.planPrice, 2)
            )

            getTextView(R.id.tv_choose_plan_item_unit).text =
                if (item.mealUnit == ConstantString.PackageUnitDay) mContext.getString(R.string.txt_per_day)
                else mContext.getString(R.string.txt_per_month)

            getTextView(R.id.tv_choose_plan_item_billed_money).text = item.billedMode


            getView(R.id.ll_choose_plan_item_discount_percent).let {
                it.visibility = if (item.popularType == ConstantInt.Type1) View.VISIBLE
                else View.INVISIBLE
            }
//            getTextView(R.id.tv_choose_plan_item_discount_percent).let {
//                it.text = "${item.discount}%"
//            }

            getView(R.id.cv_choose_plan_item_popular).let {
                if (item.popularType == ConstantInt.Type1) it.visibility = View.GONE
                else it.visibility = View.GONE
            }
        }
    }
}