package com.adealink.weparty.debug

import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.adealink.frame.mvvm.view.viewBinding
import com.adealink.weparty.R
import com.adealink.weparty.commonui.dialogfragment.BaseDialogFragment
import com.adealink.weparty.databinding.DialogSvgaCheckerReusltBinding

class ShowSvgaCheckResultTestDialog : BaseDialogFragment(R.layout.dialog_svga_checker_reuslt) {

    private val binding by viewBinding(DialogSvgaCheckerReusltBinding::bind)
    private lateinit var elist: ArrayList<String>
    private var onReturnValue: OnReturnValue? = null

    companion object {
        fun newInstance(onReturnValue: OnReturnValue): ShowSvgaCheckResultTestDialog {
            val fragment = ShowSvgaCheckResultTestDialog()
            fragment.onReturnValue = onReturnValue
            return fragment
        }
    }

    override fun initViews() {
        super.initViews()
        initData()
        initView()
    }

    private fun initData() {
        elist = ArrayList()
        elist.add("开启")
        elist.add("关闭")
    }

    private fun initView() {
        binding.titleEnv.text = "SVGA检查弹窗(会影响点击事件)"
        context?.let { it ->
            val eRecyclerView = binding.environmentList

            eRecyclerView.layoutManager = LinearLayoutManager(it)

            // itemDecoration
            eRecyclerView.addItemDecoration(
                DividerItemDecoration(
                    it,
                    DividerItemDecoration.VERTICAL
                )
            )

            // animation
            eRecyclerView.itemAnimator = DefaultItemAnimator()

            // setAdapter
            val adapter = SwitchEnvironmentAdapter(it, elist)
            eRecyclerView.adapter = adapter

            // itemClick
            adapter.setOnAccountItemClickListener(object :
                SwitchEnvironmentAdapter.IEnvironmentItemClickListener {
                override fun onItemClick(position: Int) {
                    DebugPrefs.enableShowSvgaCheckResult = position == 0
                    onReturnValue?.clickValue(ShowSvgaCheckResultTestDialog::class.java.name)
                    dialog?.dismiss()
                }
            })
        }
    }


}





