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.DataBean
import com.abbidot.tracker.constant.ConstantInt
import com.abbidot.tracker.ui.activity.set.PermissionsSetActivity
import com.abbidot.tracker.widget.TypefaceButton

/**
 *Created  by .yzq on 2024/3/25/025.
 * @link
 * @description:
 */
class PermissionsSetAdapter(
    ctx: Context, list: MutableList<DataBean>?
) : BaseRecyclerAdapter<DataBean>(ctx, list) {

    private val mPermissionsSetActivity = ctx as PermissionsSetActivity

    override fun getEmptyLayoutId(viewType: Int) = 0

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

    override fun bindData(holder: RecyclerViewHolder?, position: Int, item: DataBean) {
        val stateView = holder!!.getImageView(R.id.cb_permission_state_item)
        val typefaceTextView = holder.getTextView(R.id.tv_permission_tip_item)
        val btnLayout = holder.getView(R.id.ll_permission_set_layout)
        val btnSkip = holder.getView(R.id.btn_permission_skip_set) as TypefaceButton
        val btnEnable = holder.getView(R.id.btn_permission_enable_set) as TypefaceButton
        btnSkip.visibility = View.INVISIBLE
        btnEnable.setChangeAlphaWhenPress(true)
        btnEnable.setText(R.string.txt_turn_on_upper)

        if (item.selected) {
            typefaceTextView.visibility = View.VISIBLE
            btnLayout.visibility = View.VISIBLE
            holder.itemView.setBackgroundResource(R.drawable.shape16_white_color_bg)
        } else {
            btnLayout.visibility = View.GONE
            typefaceTextView.visibility = View.GONE
            holder.itemView.setBackgroundResource(R.drawable.shape10_white_bg)
        }

        when (item.state) {
            ConstantInt.Type0 -> stateView.setImageResource(R.drawable.icon_permission_error_check_svg)
            ConstantInt.Type1 -> stateView.setImageResource(R.drawable.icon_permission_check_svg)
        }

        holder.setText(R.id.tv_permission_name_item, item.name)
        typefaceTextView.text = item.value

        btnEnable.setOnClickListener {
            when (position) {
                0 -> mPermissionsSetActivity.mPermissionsCommon.operateBluetooth()
                1 -> mPermissionsSetActivity.mPermissionsCommon.operateGPSLocation()
                2 -> mPermissionsSetActivity.mPermissionsCommon.operateNotifications(
                    this, ConstantInt.Type0
                )
            }
        }
    }
}