package rallyedto.finishedto.fictionedto.thanedto

import android.content.Intent
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.core.view.updatePadding
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.base.datarecovery.R
import com.base.datarecovery.databinding.BeedtoBinding
import rallyedto.battleedto.acresedto.Lemonedto
import rallyedto.farewelledto.Technologyedto.showFeature
import rallyedto.policeedto.huntedto.Hiddenedto
import rallyedto.sunedto.tumouredto.majorityedto.loseedto.Togetheredto
import rallyedto.talledto.blewedto.Islandedto

class Scenarioedto : Lemonedto<BeedtoBinding>() {

    override val binding: BeedtoBinding by lazy {
        BeedtoBinding.inflate(layoutInflater)
    }
    private val mList by lazy {
        mutableListOf(
            Hiddenedto(R.mipmap.billedto, "Photo"),
            Hiddenedto(R.mipmap.rhapsodyedto, "Video"),
            Hiddenedto(R.mipmap.laceedto, "Audio"),
            Hiddenedto(R.mipmap.mixedto, "Document")
        )
    }

    override fun initView() {
        Islandedto.setStatusBarLightMode(this, true)
        Islandedto.setStatusBarColor(this, Color.TRANSPARENT)
        binding.root.updatePadding(top = Islandedto.getStatusBarHeight())
        binding.produceredto.run {
            layoutManager = LinearLayoutManager(this@Scenarioedto)
            adapter = mAdapter
        }
        Togetheredto.showNativeAd(this, binding.equaledto)
    }

    override fun initListener() {
        binding.endorseedto.setOnClickListener {
            val s = mList.filter { it.isSelect }
            if (s.isNotEmpty()) {
                startActivity(Intent(this, Farmedto::class.java))
                finish()
            } else {
                showFeature()
            }
        }
    }

    var isshow = 0

    private val mAdapter by lazy {
        class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
            val ivImage: ImageView
            val tvName: TextView
            val ivSelect: ImageView

            init {
                ivImage = view.findViewById(R.id.butterflyedto)
                tvName = view.findViewById(R.id.nurseryedto)
                ivSelect = view.findViewById(R.id.childrenedto)
            }
        }

        object : RecyclerView.Adapter<ViewHolder>() {
            override fun onCreateViewHolder(
                parent: ViewGroup,
                viewType: Int
            ): ViewHolder {
                val view = LayoutInflater.from(this@Scenarioedto)
                    .inflate(R.layout.handedto, parent, false)
                return ViewHolder(view)
            }

            override fun getItemCount() = mList.size

            override fun onBindViewHolder(holder: ViewHolder, position: Int) {
                val item = mList[position]
                holder.ivImage.setImageResource(item.imageRes)
                holder.tvName.text = item.name
                holder.itemView.setOnClickListener {
                    item.isSelect = !item.isSelect
                    holder.itemView.isSelected = item.isSelect
                    holder.ivSelect.isSelected = item.isSelect
                    isshow++
                    if (isshow < 2) {
                        Togetheredto.showNativeAd(this@Scenarioedto, binding.equaledto)
                    }

                }
            }
        }
    }
}