package com.zj365.mime.weight

import android.content.Context
import android.view.Gravity
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.xty.base.dialog.BaseDialog
import com.xty.common.recycleUtils.RecycleItem
import com.zj365.mime.adapter.ThemeAdapter
import com.zj365.mime.databinding.DialogThemeBinding

class ThemeSelectDialog(context: Context,var click:(position:Int)->Unit) : BaseDialog(context) {
    val binding by lazy{DialogThemeBinding.inflate(layoutInflater)}
    val adapter by lazy{ ThemeAdapter() }
    override fun setLayout()=binding.root
    override fun initView() {
        super.initView()
        window?.setGravity(Gravity.BOTTOM)
        initAdapter()
    }

    private fun initAdapter(){
        binding.mRecycle.addItemDecoration(RecycleItem(context,10))
        binding.mRecycle.layoutManager=LinearLayoutManager(context)
        binding.mRecycle.adapter=adapter
        adapter.setOnItemClickListener { _, view, position ->
            if(adapter.current==position){
                return@setOnItemClickListener
            }
            adapter.current=position
            click.invoke(position)
            dismiss()
        }
    }

    fun showThemeDialog(allSize:Int,current:Int){
        show()
        var list= mutableListOf<String>()
        for(i in 0 until allSize){
            list.add("主题${i+1}")
        }
        adapter.current=current
        adapter.setNewInstance(list)
    }
}