package com.keyboard.themes.key.fagment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.keyboard.themes.key.AppThemes
import com.keyboard.themes.key.R
import com.keyboard.themes.key.daapter.AdapterThemes


class FragThemes : Fragment() {

    private var paramIndex: Int = 0
    private lateinit var contentRecy: RecyclerView
    val  ARG_PARAM1 = "KEY"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            paramIndex = it.getInt(ARG_PARAM1)
        }
    }
    companion object {

        @JvmStatic
        fun newInstance(index: Int) =
            FragThemes().apply {
                arguments = Bundle().apply {
                    putInt(ARG_PARAM1, index)
                }
            }
    }
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val viewMain = inflater.inflate(R.layout.theme_layout_main_fragment, container, false)
        contentRecy = viewMain.findViewById(R.id.content_recycler)
        initContent()
        return viewMain
    }

    private fun initContent(){
        val mainBean = AppThemes.list[paramIndex]
        contentRecy.run {
            this.adapter = AdapterThemes(
                requireContext()
            ).apply {
                val shufflList = mainBean.keyboardList.shuffled()
                setForYouList(shufflList)
            }
            this.layoutManager = GridLayoutManager(requireContext(), 2)
        }
    }


}