package com.xyzshell.myphoneinfo.dashboard

import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.xyzshell.myphoneinfo.R
import com.xyzshell.myphoneinfo.databinding.FragmentSensorsBinding

class SensorsFragment : Fragment() {
private lateinit var binding: FragmentSensorsBinding


    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 = FragmentSensorsBinding.inflate(inflater, container, false)
        initView()
        binding.sensor1.root.setOnClickListener {
            val intent = Intent(requireContext(), TemperatureActivity::class.java)
            startActivity(intent)
        }
        binding.sensor2.root.setOnClickListener {
            val intent = Intent(requireContext(), SensorEachActivity::class.java)
            intent.putExtra(SensorEachActivity.TOP_TITLE, getString(R.string.accelerometer))
            startActivity(intent)
        }
        binding.sensor3.root.setOnClickListener {
            val intent = Intent(requireContext(), SensorEachActivity::class.java)
            intent.putExtra(SensorEachActivity.TOP_TITLE, getString(R.string.magnetic_field))
            startActivity(intent)
        }
        binding.sensor4.root.setOnClickListener {
            val intent = Intent(requireContext(), SensorEachActivity::class.java)
            intent.putExtra(SensorEachActivity.TOP_TITLE, getString(R.string.orientation))
            startActivity(intent)
        }
        binding.sensor5.root.setOnClickListener {
            val intent = Intent(requireContext(), SensorEachActivity::class.java)
            intent.putExtra(SensorEachActivity.TOP_TITLE, getString(R.string.light))
            startActivity(intent)
        }
        binding.sensor6.root.setOnClickListener {
            val intent = Intent(requireContext(), SensorEachActivity::class.java)
            intent.putExtra(SensorEachActivity.TOP_TITLE, getString(R.string.proximity))
            startActivity(intent)
        }
        binding.sensor7.root.setOnClickListener {
            val intent = Intent(requireContext(), SensorEachActivity::class.java)
            intent.putExtra(SensorEachActivity.TOP_TITLE, getString(R.string.gravity))
            startActivity(intent)
        }
        binding.sensor8.root.setOnClickListener {
            val intent = Intent(requireContext(), SensorEachActivity::class.java)
            intent.putExtra(SensorEachActivity.TOP_TITLE, getString(R.string.linear_acceleration))
            startActivity(intent)
        }
        binding.sensor9.root.setOnClickListener {
            val intent = Intent(requireContext(), SensorEachActivity::class.java)
            intent.putExtra(SensorEachActivity.TOP_TITLE, getString(R.string.rotation_vector))
            startActivity(intent)
        }
        binding.sensor10.root.setOnClickListener {
            val intent = Intent(requireContext(), SensorEachActivity::class.java)
            intent.putExtra(SensorEachActivity.TOP_TITLE, getString(R.string.step_counter))
            startActivity(intent)
            }
        return binding.root
    }

    private fun initView() {
        binding.sensor1.sensorName.text=getString(R.string.temperatures)
        binding.sensor2.sensorName.text=getString(R.string.accelerometer)
        binding.sensor3.sensorName.text=getString(R.string.magnetic_field)
        binding.sensor4.sensorName.text=getString(R.string.orientation)
        binding.sensor5.sensorName.text=getString(R.string.light)
        binding.sensor6.sensorName.text=getString(R.string.proximity)
        binding.sensor7.sensorName.text=getString(R.string.gravity)
        binding.sensor8.sensorName.text=getString(R.string.linear_acceleration)
        binding.sensor9.sensorName.text=getString(R.string.rotation_vector)
        binding.sensor10.sensorName.text=getString(R.string.step_counter)

        binding.hallText1.textTitle.text=getString(R.string.manufacturer)
        binding.hallText2.textTitle.text=getString(R.string.type)
        binding.hallText3.textTitle.text=getString(R.string.resolution)
        binding.hallText4.textTitle.text=getString(R.string.maximum_range)
        binding.hallText5.textTitle.text=getString(R.string.power)
        binding.hallText6.textTitle.text=getString(R.string.wakeup_sensor)

        binding.signText1.textTitle.text=getString(R.string.manufacturer)
        binding.signText2.textTitle.text=getString(R.string.type)
        binding.signText3.textTitle.text=getString(R.string.resolution)
        binding.signText4.textTitle.text=getString(R.string.maximum_range)
        binding.signText5.textTitle.text=getString(R.string.power)
        binding.signText6.textTitle.text=getString(R.string.wakeup_sensor)

        binding.geoText1.textTitle.text=getString(R.string.manufacturer)
        binding.geoText2.textTitle.text=getString(R.string.type)
        binding.geoText3.textTitle.text=getString(R.string.resolution)
        binding.geoText4.textTitle.text=getString(R.string.maximum_range)
        binding.geoText5.textTitle.text=getString(R.string.power)
        binding.geoText6.textTitle.text=getString(R.string.wakeup_sensor)

        binding.rpcText1.textTitle.text=getString(R.string.manufacturer)
        binding.rpcText2.textTitle.text=getString(R.string.type)
        binding.rpcText3.textTitle.text=getString(R.string.resolution)
        binding.rpcText4.textTitle.text=getString(R.string.maximum_range)
        binding.rpcText5.textTitle.text=getString(R.string.power)
        binding.rpcText6.textTitle.text=getString(R.string.wakeup_sensor)

    }

    companion object {
        /**
         * Use this factory method to create a new instance of
         * this fragment using the provided parameters.
         *
         * @param param1 Parameter 1.
         * @param param2 Parameter 2.
         * @return A new instance of fragment SensorsFragment.
         */
        // TODO: Rename and change types and number of parameters
        @JvmStatic
        fun newInstance() =
            SensorsFragment().apply {
                arguments = Bundle().apply {

                }
            }
    }
}