package com.themes.fancy.keyboard.keyboard.viewui

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.themes.fancy.keyboard.keyboard.MyApplication
import com.themes.fancy.keyboard.keyboard.R
import com.themes.fancy.keyboard.keyboard.myada.MainAdapter

private const val ARG_PARAM1 = "list_index"

class FragmentMain : Fragment() {

    private var paramIndex: Int = 0
    private lateinit var contentRecy:RecyclerView

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

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

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


}