package com.blue.running.keyboard.run_frag

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.blue.running.keyboard.RunningApp
import com.blue.running.keyboard.databinding.FragMainBinding
import com.blue.running.keyboard.run_activity.ActivityList
import com.blue.running.keyboard.run_adapter.AdapterMain
import com.blue.running.keyboard.run_api.ApiClickList

class FragMain : Fragment() {


    private lateinit var vb: FragMainBinding



    lateinit var viewAllList: MutableList<com.blue.running.keyboard.run_jsonbean.ClassData>
    private lateinit var adapterMain: AdapterMain

    private var recommendDialog: DialogMore? = null

    companion object {

        @JvmStatic
        fun newInstance() =
            FragMain()
    }

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


    private fun setTabRecycler() {
        viewAllList = RunningApp.list.subList(1, RunningApp.list.size)
        adapterMain = AdapterMain(
            requireContext(), viewAllList
        ).apply {
            setClickAction(object : ApiClickList {
                override fun OnClickSeeAll(name: String) {
                    startActivity(Intent(requireContext(),
                        ActivityList::class.java).apply {
                        putExtra(ActivityList.KEY_NAME,name)
                    })

                }

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

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

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


}