package com.app.input.breeze.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 com.app.input.breeze.board.App
import com.app.input.breeze.board.bean.CategoryWrapper
import com.app.input.breeze.board.databinding.HomeFragmentBinding
import com.app.input.breeze.board.callback.ViewAllClickListener
import com.app.input.breeze.board.listutils.CategoryListAdapter
import com.app.input.breeze.board.uiactivity.ThemeListActivity

class HomeFragment : Fragment() {


    private lateinit var vb: HomeFragmentBinding



    lateinit var viewAllList: MutableList<CategoryWrapper>
    private lateinit var adapterParent: CategoryListAdapter



    companion object {

        @JvmStatic
        fun newInstance() =
            HomeFragment()
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        vb = HomeFragmentBinding.inflate(layoutInflater)

        setTabRecycler()

        return vb.root
    }


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

                }

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




}