package com.tools.device.devcheck.dashboard

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import com.tools.device.devcheck.base.BaseFragment
import com.tools.device.devcheck.databinding.FragmentDashboardBinding


private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

class DashboardFragment : BaseFragment<FragmentDashboardBinding>() {

    private var param1: String? = null
    private var param2: String? = null

    private var dialogBattery: DialogBattery? = null
    private var dialogNetwork: DialogNetwork? = null
    private var dialogDisplay: DialogDisplay? = null

    companion object {
        @JvmStatic
        fun newInstance() =
            DashboardFragment().apply {
                arguments = Bundle().apply {
//                    putString(ARG_PARAM1, param1)
//                    putString(ARG_PARAM2, param2)
                }
            }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
//            param1 = it.getString(ARG_PARAM1)
//            param2 = it.getString(ARG_PARAM2)
        }
    }


    override fun getViewBinding(
        inflater: LayoutInflater,
        container: ViewGroup?
    ): FragmentDashboardBinding {
        return FragmentDashboardBinding.inflate(inflater, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        initCpu()
        initClick()


    }

    private fun initCpu() {
        binding.layoutCpu.run {
            recyclerCpu.run {
                adapter = CpuAdapter(requireContext()).apply {
                    setData(
                        listOf(
                            "1804 MHz",
                            "1804 MHz",
                            "1804 MHz",
                            "1804 MHz",
                            "1804 MHz",
                            "1804 MHz",
                            "1804 MHz",
                            "1804 MHz"
                        )
                    )
                }
                layoutManager = GridLayoutManager(requireContext(), 2)

            }
        }

    }

    private fun initClick() {
        binding.layoutCenter.run {
            relayoutBattery.setOnClickListener {
                dialogBattery = dialogBattery ?: DialogBattery()
                dialogBattery?.show(parentFragmentManager, "")
            }
            relayoutNetwork.setOnClickListener {
                dialogNetwork = dialogNetwork ?: DialogNetwork()
                dialogNetwork?.show(parentFragmentManager, "")
            }
            relayoutDisplay.setOnClickListener {
                dialogDisplay = dialogDisplay?: DialogDisplay()
                dialogDisplay?.show(parentFragmentManager, "")
            }
        }
    }

}