package com.input.board.appskey.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.input.board.appskey.keyboard.R
import com.input.board.appskey.keyboard.recyAdapter.ForYouAdapter

private const val ARG_PARAM1 = "list_index"

class FragmentContent : 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) =
            FragmentContent().apply {
                arguments = Bundle().apply {
                    putInt(ARG_PARAM1, index)
                }
            }
    }
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val viewMain = inflater.inflate(R.layout.fragment_content, container, false)
        contentRecy = viewMain.findViewById(R.id.content_recycler)
        initContent()
        return viewMain
    }

    private fun initContent(){
        val viewAllActivity = requireActivity() as ViewAllActivity
        val mainBean = viewAllActivity.viewAllList[paramIndex]
        contentRecy.run {
            this.adapter = ForYouAdapter(requireContext()).apply {
                val shufflList = mainBean.keyboardList.shuffled()
                setForYouList(shufflList)
            }
            this.layoutManager = GridLayoutManager(requireContext(),2)
        }
    }


}