package com.color.keyboard.black.myfragment

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.color.keyboard.black.ColorApp
import com.color.keyboard.black.activity.SeeActivity
import com.color.keyboard.black.adapter.AdapterHome
import com.color.keyboard.black.bean.ClassData
import com.color.keyboard.black.databinding.LayoutFragmentMainBinding
import com.color.keyboard.black.myapi.ClickAllApi

class FragmentOne : Fragment() {


    private lateinit var vb: LayoutFragmentMainBinding



    lateinit var viewAllList: MutableList<ClassData>
    private lateinit var adapterHome: AdapterHome

    private var recommendDialog: DialogRecom? = null

    companion object {

        @JvmStatic
        fun newInstance() =
            FragmentOne()
    }

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


    private fun setTabRecycler() {
        viewAllList = ColorApp.list.subList(1, ColorApp.list.size)
        adapterHome = AdapterHome(
            requireContext(), viewAllList
        ).apply {
            setClickAction(object : ClickAllApi {
                override fun OnClickSeeAll(name: String) {
                    startActivity(Intent(requireContext(),
                        SeeActivity::class.java).apply {
                        putExtra(SeeActivity.KEY_NAME,name)
                    })

                }

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

    private fun showRecommend() {
        if (recommendDialog == null) {
            recommendDialog = DialogRecom.newInstance() {

            }
        }
        recommendDialog?.show(childFragmentManager, "")
    }


}