package com.clement.karaokefrog.jkdsfhjkdshfjksdf


import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.*
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.clement.karaokefrog.R
import com.clement.karaokefrog.sjhkdgkjhfsgkjfhs.SharedPrefs
import com.clement.karaokefrog.jdfhjsdfhkdfsh.sjkdhkjdshdskjds
import com.clement.karaokefrog.databinding.JsdkhgkjdsghksgdBinding


var sdhjkdshdskhds = ""

class Web_fragmint : Fragment() {
    var checkEror = false
    val sjdkhjkdfhskjdh by lazy { JsdkhgkjdsghksgdBinding.inflate(layoutInflater) }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        SharedPrefs(requireContext()).jdshjkfh(SharedPrefs.jdfhkjhfd)


        (requireContext() as sjkdhkjdshdskjds).dshjsdkhdsjds = {}
        val jdskhsdhkjds = WebChromeClient()
        sjdkhjkdfhskjdh.kldsjsdljds.setWebChromeClient(jdskhsdhkjds)
        Log.d("test12", "doneUrl: $sdhjkdshdskhds")

        with(sjdkhjkdfhskjdh.kldsjsdljds) {
            (requireContext() as sjkdhkjdshdskjds).dshjsdkhdsjds = { goBack() }
            settings.loadsImagesAutomatically = true
            webViewClient = kldsjdsljds()
            settings.allowFileAccess = true
            settings.mixedContentMode = 0
            settings.javaScriptEnabled = true
            settings.javaScriptCanOpenWindowsAutomatically = true
            settings.javaScriptEnabled = true
            settings.domStorageEnabled = true
                loadUrl(sdhjkdshdskhds)
            //      loadUrl(
           //    "https://trackyourtraff.com/key?sub1=test1&sub2=test2&sub3=test3&sub4=test4&sub5=test5&sub6=test&sub7=6&sub9=4fb2fb41-0189-1000-94a6-cfe79150eca6&sub10=09e13eeb-6ba3-4732-b7d2-6159187ecb0c&sub11=1689259278052-7205833029739453166"
          //  " https://mostbetru-60.com/?"
          //  )
            Handler(Looper.getMainLooper()).postDelayed({
            sjdkhjkdfhskjdh.zug.isVisible = false
                                                        },1500L)
            Log.d("test13", sdhjkdshdskhds)

        }


    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        return sjdkhjkdfhskjdh.root
    }


    inner class kldsjdsljds : WebViewClient() {



 var erorCode = 0
        override fun onReceivedError(
            view: WebView?,
            request: WebResourceRequest?,
            error: WebResourceError?
        ) {
           /* Log.d("test32","checkEror")
            checkEror = true
            Handler(Looper.getMainLooper()).postDelayed({
            Log.d("test30",erorCode.toString())
            if(erorCode == 401) {
                sjdkhjkdfhskjdh.zug.isVisible = false

            }else{
                findNavController().navigate(R.id.kdjsjglksdjgsjdglkjdgdslkjgds)*/
          /*  }
                                                        },2500L)*/
            super.onReceivedError(view, request, error)
        }


        override fun onReceivedHttpError(
            view: WebView?,
            request: WebResourceRequest?,
            error: WebResourceResponse?
        ) {
            Log.d("test28",request.toString())
            Log.d("test29", error?.statusCode.toString())
            erorCode = error?.statusCode?:0
         /*   if (error?.statusCode == 404) {

              try {
                    findNavController().navigate(R.id.kdjsjglksdjgsjdglkjdgdslkjgds)
                } catch (_: Exception) {
                   /*   findNavController().navigate(R.id.kdjsjglksdjgsjdglkjdgdslkjgds)
*/
                }
            }*/
        }


        override fun onPageFinished(view: WebView?, url: String?) {
            super.onPageFinished(view, url)

        }
    }

}