package com.xyzshell.myphoneinfo.dashboard

import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.xyzshell.myphoneinfo.R
import com.xyzshell.myphoneinfo.adapter.AppListAdapter
import com.xyzshell.myphoneinfo.databinding.FragmentAppsBinding
import com.xyzshell.myphoneinfo.dialog.AppDialogFragment
import com.xyzshell.myphoneinfo.dialog.BottomDialogFragment
import com.xyzshell.myphoneinfo.main.MainScrollActivity

class AppsFragment : Fragment(),AppListAdapter.OnShowDialogListener {
    private lateinit var binding: FragmentAppsBinding
    private lateinit var dialogFragment: AppDialogFragment
    private lateinit var bottomDialog: BottomDialogFragment
    private var sel: Int? = 0
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        binding = FragmentAppsBinding.inflate(inflater, container, false)
        val adapter= AppListAdapter()
        adapter.setOnclickListener(this)
        binding.recyclerView.adapter = adapter
        binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
       binding.llTitle.setOnClickListener {
           bottomDialog= BottomDialogFragment(type = "apps", sel = sel, invoke = {item->
               sel = item
               binding.tvTitle.text=when(item){
                    0 -> "User(23)"
                    1 -> "System(23)"
                    2 -> "All(23)"
                   else -> "User"
               }
           })
           Log.d("sel", sel.toString())
           bottomDialog.show(requireActivity().supportFragmentManager, "BottomDialogFragment")
       }

        return binding.root
    }

    companion object {
        @JvmStatic
        fun newInstance() =
            AppsFragment().apply {
                arguments = Bundle().apply {

                }
            }
    }

    override fun onShowAppSelectDialog() {
         dialogFragment = AppDialogFragment()
         dialogFragment.show(requireActivity().supportFragmentManager, "AppDialogFragment")
    }
}