package com.abbidot.tracker.deprecated.adapter

import android.content.Context
import androidx.appcompat.widget.AppCompatCheckedTextView
import androidx.core.content.ContextCompat
import com.abbidot.baselibrary.list.BaseRecyclerAdapter
import com.abbidot.baselibrary.list.RecyclerViewHolder
import com.abbidot.tracker.R
import com.abbidot.tracker.bean.MenuTxtBean
import com.abbidot.tracker.util.ViewUtil


/**
 *Created  by .yzq on 2022/3/29/029.
 * @link
 * @description:
 */
class SelectPaymentMethodAdapter(
    ctx: Context, list: MutableList<MenuTxtBean>?, showPaypal: Boolean = true
) : BaseRecyclerAdapter<MenuTxtBean>(ctx, list) {

    private val mShowPaypal = showPaypal

    override fun getEmptyLayoutId(viewType: Int) = 0

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

    override fun bindData(holder: RecyclerViewHolder?, position: Int, item: MenuTxtBean) {
        ViewUtil.instance.setShapeRadius(holder!!.itemView, 6)
        val textView = holder.getTextView(R.id.item_payment_method_text_view)
        textView.setCompoundDrawablesWithIntrinsicBounds(
            item.imageId, 0, 0, 0
        )
        (holder.getView(R.id.item_payment_method_checkbox) as AppCompatCheckedTextView).isChecked =
            item.isSwitch

        if (mShowPaypal && (position == 0 || position == getData().size - 1)) {
            textView.text = item.menuName
        } else if (position == getData().size - 1) {
            textView.text = item.menuName
        } else {
            val str = item.menuName
            var cardFormat = str.substring(0, 4)
            for (i in 0 until str.length - 8) {
                cardFormat = "$cardFormat*"
            }
            cardFormat += str.substring(str.length - 4, str.length)
            textView.text = cardFormat
        }
    }
}