package com.keyborad.theme.trendyborad.trendyuifragment

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.keyborad.theme.trendyborad.TrendyApp
import com.keyborad.theme.trendyborad.bean.BeanWrapper
import com.keyborad.theme.trendyborad.databinding.FragmentHomeBinding
import com.keyborad.theme.trendyborad.trendycallback.TrendyViewAllCallback
import com.keyborad.theme.trendyborad.trendylistutils.TrendyHomeAdapter
import com.keyborad.theme.trendyborad.trendyuiactivity.TrendyCategoryListActivity

class TrendyFragmentHome : Fragment() {


    private lateinit var vb: FragmentHomeBinding



    lateinit var viewAllList: MutableList<BeanWrapper>
    private lateinit var adapterParent: TrendyHomeAdapter



    companion object {

        @JvmStatic
        fun newInstance() =
            TrendyFragmentHome()
    }

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

        setTabRecycler()

        return vb.root
    }


    private fun setTabRecycler() {
        viewAllList = TrendyApp.Companion.list
        adapterParent = TrendyHomeAdapter(
            requireContext(), viewAllList
        ).apply {
            setClickAction(object : TrendyViewAllCallback {
                override fun OnClickSeeAll(name: String) {
                    startActivity(Intent(requireContext(),
                        TrendyCategoryListActivity::class.java).apply {
                        putExtra(TrendyCategoryListActivity.KEY_NAME,name)
                    })

                }

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




}