package com.xyzshell.myphoneinfo.dashboard

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.FragmentNetworkBinding
import com.xyzshell.myphoneinfo.dialog.ShowLoadFragment

class NetworkFragment : Fragment() {

    private var status=1//0:未连接，1：已连接
private lateinit var binding:FragmentNetworkBinding
    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 = FragmentNetworkBinding.inflate(inflater, container, false)
//        binding.signalStrength.setStrength(4)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        //connection
        binding.networkLayout.wfText1.textTitle.text=getString(R.string.status)
        binding.networkLayout.wfText2.textTitle.text=getString(R.string.network)
        binding.networkLayout.wfText3.textTitle.text=getString(R.string.bssid)
        binding.networkLayout.wfText4.textTitle.text=getString(R.string.function)
        binding.networkLayout.wfText5.textTitle.text=getString(R.string.connection_speed)
        binding.networkLayout.wfText6.textTitle.text=getString(R.string.signal_strength)
        binding.networkLayout.wfText7.textTitle.text=getString(R.string.frequency)
        binding.networkLayout.wfText8.textTitle.text=getString(R.string.frequency_band)
        binding.networkLayout.wfText9.textTitle.text=getString(R.string.channel)
        binding.networkLayout.wfText10.textTitle.text=getString(R.string.standard)

        //dhcp
        binding.networkLayout.dhText1.textTitle.text=getString(R.string.dhcp_server)
        binding.networkLayout.dhText2.textTitle.text=getString(R.string.dhcp_lease_time)
        binding.networkLayout.dhText3.textTitle.text=getString(R.string.gateway)
        binding.networkLayout.dhText4.textTitle.text=getString(R.string.subnet_mask)
        binding.networkLayout.dhText5.textTitle.text=getString(R.string.dns1)
        binding.networkLayout.dhText6.textTitle.text=getString(R.string.dns2)
        binding.networkLayout.dhText7.textTitle.text=getString(R.string.ip_address)
        binding.networkLayout.dhText8.textTitle.text=getString(R.string.ipv6)

        //mobel
        binding.mdText1.textTitle.text=getString(R.string.dual_sim_dual_standby)
        binding.mdText2.textTitle.text=getString(R.string.phone_type)
        binding.mdText3.textTitle.text=getString(R.string.esim)

        binding.conTexts.textTitle.text=getString(R.string.status)

        binding.defText1.textTitle.text=getString(R.string.data)

        binding.defText2.textTitle.text=getString(R.string.voice)
        binding.defText3.textTitle.text=getString(R.string.short_message)

        binding.simText1.textTitle.text=getString(R.string.status)
        binding.simText2.textTitle.text=getString(R.string.nation)
        binding.simText3.textTitle.text=getString(R.string.roaming)
        binding.simText4.textTitle.text=getString(R.string.network_type)


        if(status==0){
            binding.noConnect.visibility=View.VISIBLE
            binding.connectData.visibility=View.GONE
            binding.networkLayout.wfText1.textContent.text="Disconnected"
            binding.networkLayout.wifiList.visibility=View.GONE
            binding.networkLayout.llPubShow.visibility=View.GONE
        }else{
            binding.noConnect.visibility=View.GONE
            binding.connectData.visibility=View.VISIBLE
            binding.networkLayout.wfText1.textContent.text="Connected"
            binding.networkLayout.wifiList.visibility=View.VISIBLE
            binding.networkLayout.llPubShow.visibility=View.VISIBLE
        }
        binding.networkLayout.pubShow.setOnClickListener{
            val tag = "showLoadFragment"
            if (requireActivity().supportFragmentManager.findFragmentByTag(tag) == null) {
                val showLoadFragment = ShowLoadFragment()
                showLoadFragment.show(requireActivity().supportFragmentManager, tag)
            }
        }
    }

    companion object {

        @JvmStatic
        fun newInstance() =
            NetworkFragment().apply {
                arguments = Bundle().apply {

                }
            }
    }
}