package es.verdnatura.presentation.view.feature.controlador.fragment


import android.webkit.WebChromeClient
import es.verdnatura.R
import es.verdnatura.databinding.FragmentWebBinding
import es.verdnatura.presentation.base.BaseFragment
import es.verdnatura.presentation.view.component.CustomDialog


class WebFragment(
    var entryPoint: String = ""
) : BaseFragment<FragmentWebBinding, ControladorViewModel>(ControladorViewModel::class) {

    override fun getLayoutId(): Int = R.layout.fragment_web
    private lateinit var customDialog: CustomDialog

    companion object {
        fun newInstance(entryPoint: String) = WebFragment(entryPoint)
    }

    override fun init() {


        customDialog = CustomDialog(requireContext())
        setToolbar()
        setWeb()
        super.init()
    }

    private fun setWeb() {

        binding.webView.setWebChromeClient (WebChromeClient())

        //binding.webView.getSettings (). setJavaScriptEnabled (true)
       // sergio:deprecated
        //webView.getSettings (). setPluginState (WebSettings.PluginState.ON)
        val webSettings = binding.webView.settings
        webSettings.javaScriptEnabled = true
        webSettings.domStorageEnabled = true
        webSettings.loadWithOverviewMode = true
        webSettings.useWideViewPort = true
        webSettings.builtInZoomControls = true
        webSettings.displayZoomControls = false
        webSettings.setSupportZoom(true)
        //webSettings.defaultTextEncodingName = "utf-8"


        binding.webView.loadUrl ("https://salix.verdnatura.es/#!/item/$entryPoint/summary")

       // val openURL = Intent(Intent.ACTION_VIEW)
      //  openURL.data = Uri.parse("https://salix.verdnatura.es/#!/ticket/3271614/tracking/index")
       // openURL.data = Uri.parse("https://salix.verdnatura.es/#!/item/index")
       // startActivity(openURL)

    }

    private fun setToolbar() {

        binding.mainToolbar.toolbarTitle.text = getString(R.string.item)+entryPoint
      //  binding.splashProgress.visibility= View.GONE
    }




}

