package com.app.input.color.board.uifragment

import android.content.Intent
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.LinearLayoutManager
import androidx.viewpager.widget.ViewPager
import com.app.input.color.board.App
import com.app.input.color.board.bean.BeanWrapper
import com.app.input.color.board.databinding.FragmentHomeBinding
import com.app.input.color.board.callback.ViewAllCallback
import com.app.input.color.board.listutils.HomeAdapter
import com.app.input.color.board.uiactivity.CategoryListActivity

class FragmentHome : Fragment() {


    private lateinit var vb: FragmentHomeBinding


    private lateinit var viewContent: ViewPager
    lateinit var viewAllList: MutableList<BeanWrapper>
    private lateinit var adapterParent: HomeAdapter



    companion object {

        @JvmStatic
        fun newInstance() =
            FragmentHome()
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        vb = FragmentHomeBinding.inflate(layoutInflater)
//        viewContent = vb.viewPager
        setTabRecycler()

        return vb.root
    }


    private fun setTabRecycler() {
        viewAllList = App.Companion.list
        adapterParent = HomeAdapter(
            requireContext(), viewAllList
        ).apply {
            setClickAction(object : ViewAllCallback {
                override fun OnClickSeeAll(name: String) {
                    startActivity(Intent(requireContext(),
                        CategoryListActivity::class.java).apply {
                        putExtra(CategoryListActivity.KEY_NAME,name)
                    })

                }

            })
        }
        vb.tabRecycler.run {
            adapter = adapterParent
            layoutManager = LinearLayoutManager(requireContext())
        }
    }




}