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.FencesBean
import com.abbidot.tracker.constant.ConstantInt
import com.abbidot.tracker.util.ViewUtil
import com.abbidot.tracker.widget.TypefaceRoundButton

/**
 *
 */
class FencesZoneAdapter(
    ctx: Context, list: MutableList<FencesBean>?, isShowRightArrow: Boolean = true
) : BaseRecyclerAdapter<FencesBean>(ctx, list) {

    private var isShowRightArrow = true

    init {
        this.isShowRightArrow = isShowRightArrow
    }

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

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

    override fun noData(holder: RecyclerViewHolder?) {
        holder?.apply {
            getView(R.id.btn_empty_fences_add_safe_zone).visibility =
                if (isShowNoDataAddButton) View.VISIBLE
                else View.GONE
        }
    }

    override fun bindData(holder: RecyclerViewHolder?, position: Int, item: FencesBean) {
        holder!!.getTextView(R.id.tv_virtual_fences_list_name).text = item.name
        holder.getTextView(R.id.tv_virtual_fences_list_address).text = item.address

        val fenceNameTypeImage = ViewUtil.instance.getFenceNameImageType(item.fenceNameType)

        holder.getImageView(R.id.iv_virtual_fences_list_type).setImageResource(fenceNameTypeImage)

        val typefaceButton =
            holder.getView(R.id.tv_virtual_fences_list_switch_state) as TypefaceRoundButton
        val switchText: String
        val switchTextColor: Int
        val switchStrokeColor = if (item.isOn == ConstantInt.Open) {
            switchText = mContext.getString(R.string.txt_active)
            switchTextColor = ContextCompat.getColor(mContext, R.color.green_color100)
            ContextCompat.getColor(mContext, R.color.green_color100)
        } else {
            switchText = mContext.getString(R.string.txt_deactivate)
            switchTextColor = ContextCompat.getColor(mContext, R.color.block_color2)
            ContextCompat.getColor(mContext, R.color.white_gray_color1)
        }
        typefaceButton.apply {
            text = switchText
            setTextColor(switchTextColor)
            setStrokeColors(ColorStateList.valueOf(switchStrokeColor))
        }

        if (isShowRightArrow) {
            holder.getView(R.id.iv_virtual_fences_list_arrow_right).visibility = View.VISIBLE
        } else {
            holder.getView(R.id.iv_virtual_fences_list_arrow_right).visibility = View.INVISIBLE
        }
    }

}