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.tracker.R
import com.abbidot.tracker.bean.FamilyBean
import com.abbidot.tracker.constant.ConstantInt
import com.abbidot.tracker.ui.activity.pet.FamilyMembersActivity
import com.qmuiteam.qmui.layout.QMUIButton

/**
 *Created  by .yzq on 2024/2/21/021.
 * @link
 * @description:
 */
class FamilyMembersAdapter(
    ctx: Context, list: MutableList<FamilyBean>?
) : BaseRecyclerAdapter<FamilyBean>(ctx, list) {

    private val mFamilyMembersActivity: FamilyMembersActivity

    init {
        mFamilyMembersActivity = ctx as FamilyMembersActivity
    }

    override fun getEmptyLayoutId(viewType: Int) = 0

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

    override fun bindData(holder: RecyclerViewHolder?, position: Int, item: FamilyBean) {
        val activeState = holder!!.getView(R.id.tv_family_member_active_state)
        val pendingState = holder.getView(R.id.tv_family_member_pending_state)
        val resendBtn = holder.getView(R.id.btn_family_member_resend) as QMUIButton
        val avatarImageView = holder.getImageView(R.id.il_family_member_head)
        resendBtn.setChangeAlphaWhenPress(true)
        if (item.status == ConstantInt.Open) {
            activeState.visibility = View.VISIBLE
            pendingState.visibility = View.GONE
            resendBtn.visibility = View.GONE
        } else {
            activeState.visibility = View.INVISIBLE
            pendingState.visibility = View.VISIBLE
            resendBtn.visibility = View.VISIBLE
        }
        holder.setText(R.id.tv_family_member_email, item.acceptEmail)

        val avatarImageResId = if (item.avatar == ConstantInt.Man) {
            R.drawable.icon_family_boy_avatar
        } else {
            R.drawable.icon_family_girl_avatar
        }
        avatarImageView.setImageResource(avatarImageResId)

        holder.setClickListener(R.id.iv_delete_family_member_btn, View.OnClickListener {
            mFamilyMembersActivity.deleteFamily(item)
        })
        resendBtn.setOnClickListener {
            mFamilyMembersActivity.resendFamily(item)
        }
    }
}