package com.abbidot.tracker.adapter

import android.content.Context
import android.content.res.ColorStateList
import android.view.View
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.WiFiZoneBean
import com.abbidot.tracker.constant.ConstantInt
import com.abbidot.tracker.widget.TypefaceRoundButton
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButtonDrawable

/**
 */
class WiFiZoneAdapter(
    ctx: Context, list: MutableList<WiFiZoneBean>?, isShowArrowRight: Boolean = true
) : BaseRecyclerAdapter<WiFiZoneBean>(ctx, list) {

    private val isShowArrow = isShowArrowRight

    //禁用模式,无法点击的情况
    private var isDisabledMode = true

    override fun getEmptyLayoutId(viewType: Int) = R.layout.layout_virtual_fences_empty_view

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

    override fun noData(holder: RecyclerViewHolder?) {
        holder?.apply {
            getTextView(R.id.tv_fences_add_wifi_no_title).let {
                val tColor = if (isDisabledMode) R.color.grey_color
                else R.color.data_black_color
                it.setTextColor(ContextCompat.getColor(mContext, tColor))
            }
            (getView(R.id.btn_empty_fences_add_safe_zone) as TypefaceRoundButton).let {
                it.visibility = if (isShowNoDataAddButton) View.VISIBLE
                else View.GONE
                val tColor = if (isDisabledMode) R.color.grey_color
                else R.color.select_color
                it.setTextColor(ContextCompat.getColor(mContext, tColor))
                (it.background as QMUIRoundButtonDrawable).let { d ->
                    val dColor = if (isDisabledMode) R.color.grey_color
                    else R.color.btn_color
                    d.setStrokeColors(
                        ColorStateList.valueOf(
                            ContextCompat.getColor(
                                mContext, dColor
                            )
                        )
                    )
                }
            }
        }
    }

    override fun bindData(holder: RecyclerViewHolder?, position: Int, item: WiFiZoneBean) {
        holder!!.setText(R.id.tv_wifi_zone_name, item.wifiZoneName)
        holder.setText(R.id.tv_wifi_zone_address, item.address)
        val wifiZoneTypeImage =
            if (item.type == ConstantInt.Type1) R.drawable.icon_wifi_zone_type1_svg
            else R.drawable.icon_wifi_zone_type2_svg
        holder.getImageView(R.id.iv_wifi_zone_type).setBackgroundResource(wifiZoneTypeImage)

        holder.getImageView(R.id.iv_wifi_zone_list_arrow_right).visibility =
            if (isShowArrow) View.VISIBLE
            else View.GONE
    }

    fun setDisabledMode(isDisabled: Boolean) {
        isDisabledMode = isDisabled
        notifyDataSetChanged()
    }
}