package com.sambath.kunkhmer.screen.lives

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.WebView
import android.webkit.WebViewClient
import com.sambath.kunkhmer.R

class LiveDetailFragment : Fragment() {
    private var _root: View? = null
    private val binding get() = _root!!

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        _root = inflater.inflate(R.layout.fragment_live_detail, container, false)

        // Retrieve data from arguments
        val imageUrl = arguments?.getString("image_url")
        val title = arguments?.getString("title")
        val description = arguments?.getString("description")
        val link = arguments?.getString("url") ?: "https://youtu.be/SyheySKTg-U?si=RCK3NV6AgSKEV6cM"
        //val link = "https://youtu.be/SyheySKTg-U?si=RCK3NV6AgSKEV6cM"

        val webView = binding.findViewById<WebView>(R.id.webView)

        // Load a YouTube video by specifying the video URL
        val youtubeVideoUrl = link
        webView.settings.javaScriptEnabled = true
        webView.webViewClient = WebViewClient()
        webView.loadUrl(youtubeVideoUrl)

        return binding
    }
}