package com.sambath.kunkhmer.screen.main

import android.annotation.SuppressLint
import android.media.MediaPlayer
import android.os.Bundle
import android.view.View
import android.view.animation.AlphaAnimation
import android.view.animation.Animation
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.sambath.kunkhmer.R
import com.sambath.kunkhmer.adapter.MainPagerAdapter
import com.sambath.kunkhmer.app.App
import com.sambath.kunkhmer.app.ShareActivity
import com.sambath.kunkhmer.base.BaseFragment
import com.sambath.kunkhmer.extension.btnClick
import com.sambath.kunkhmer.remote.User
import com.sambath.kunkhmer.screen.main.cflive.Betting.CfBetFragment
import com.sambath.kunkhmer.screen.main.cflive.result.CfResultFragment
import com.sambath.kunkhmer.screen.report.StatementFragment
import com.sambath.kunkhmer.screen.setting.SettingFragment
import com.sambath.kunkhmer.view.SettingButtonView

/**
 * A simple [Fragment] subclass as the default destination in the navigation.
 */
class MainFragment : BaseFragment(R.layout.fragment_main) {
//    private val TAB_TITLES = arrayOf(
//        R.string.current_bets,
//        R.string.today_report,
//    )
//    private lateinit var mainViewModel: MainViewModel
//    private val shareViewModel = App.injectShareViewModel()
//    private val sharePref = App.injectPrefHelper()
//    private lateinit var user: User
//    private lateinit var btnPlay: SettingButtonView
//    private lateinit var btnResult: SettingButtonView
//    private lateinit var betTouch: MediaPlayer
//    lateinit var result: MediaPlayer
//    private var anim: AlphaAnimation? = null
//    override fun onCreate(savedInstanceState: Bundle?) {
////        mainViewModel = MainViewModel(App.injectApiService(), App.injectPrefHelper())
//        super.onCreate(savedInstanceState)
//        //companyInfoId =arguments?.getInt(COM_INTO_ID_KEY) ?: 0
//        (requireActivity() as ShareActivity).apply {
//            user = userShare
//        }
//        anim = AlphaAnimation(0.0f, 1.0f)
//        anim?.duration = 50 //You can manage the blinking time with this parameter
//        anim?.startOffset = 50
//        anim?.repeatMode = Animation.REVERSE
//        anim?.repeatCount = Animation.INFINITE
//    }
//
//    @SuppressLint("CheckResult")
//    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
//        super.onViewCreated(view, savedInstanceState)
////        mainViewModel.state.observe(viewLifecycleOwner, androidx.lifecycle.Observer {
////            getMainData(it)
////        })
////        mainViewModel.getMainData()
////        (requireActivity() as ShareActivity).apply {
////            userNameTextView.text = user.userName
////        }
//        val mainPagerAdapter = MainPagerAdapter(requireActivity() as ShareActivity)
//        val viewPager: ViewPager2 = view.findViewById(R.id.view_pager)
//        viewPager.adapter = mainPagerAdapter
//        val tabs: TabLayout = view.findViewById(R.id.tabLayout)
//        TabLayoutMediator(
//            tabs, viewPager
//        ) { tab, position -> // Styling each tab here
//            tab.text = getString(TAB_TITLES[position])
//        }.attach()
////        shareViewModel.getConnectivityStates.observe(viewLifecycleOwner, Observer {
////            getSocketConectionStatus(it)
////        })
//        btnPlay = view.findViewById(R.id.btn_play)
//        btnPlay.setOnClickListener {
////            if (!sharePref.getIsMute()) betTouch.start()
//            it.btnClick().subscribe {
////                btnPlay.isEnabled = false
//                (requireActivity() as? ShareActivity)?.apply {
//                    supportFragmentManager.beginTransaction()
//                        .setCustomAnimations(
//                            R.anim.slide_in,
//                            R.anim.slide_out,
//                            R.anim.slide_in_exit,
//                            R.anim.slide_out_exit
//                        )
//                        .add(R.id.container, CfBetFragment().apply {
//                            arguments =
//                                Bundle().apply {
//                                    // putInt(Fragment7.COM_INFO_ID_KEY, companyInfoId)
//                                }
//                        })
//                        .addToBackStack(null)
//                        .commit()
//                }
//            }
//        }
//        btnResult = view.findViewById(R.id.btn_result)
//        btnResult.setOnClickListener {
////            if (!sharePref.getIsMute()) betTouch.start()
//            it.btnClick().subscribe {
////                btnResult.isEnabled = false
//                (requireActivity() as? ShareActivity)?.apply {
//                    supportFragmentManager.beginTransaction()
//                        .setCustomAnimations(
//                            R.anim.slide_in,
//                            R.anim.slide_out,
//                            R.anim.slide_in_exit,
//                            R.anim.slide_out_exit
//                        )
//                        .add(R.id.container, CfResultFragment().apply {
//                            arguments =
//                                Bundle().apply {
//                                    // putInt(Fragment7.COM_INFO_ID_KEY, companyInfoId)
//                                }
//                        })
//                        .addToBackStack(null)
//                        .commit()
//                }
//            }
//        }
//        (requireActivity() as? ShareActivity)?.apply {
//            groupToolbarIcons.isVisible = true
//            layCfStatus.isVisible = true
//            settingImageView.setOnClickListener {
////                if (!sharePref.getIsMute()) betTouch.start()
//                it.btnClick().subscribe {
//                    supportFragmentManager.beginTransaction()
//                        .setCustomAnimations(
//                            R.anim.slide_in,
//                            R.anim.slide_out,
//                            R.anim.slide_in_exit,
//                            R.anim.slide_out_exit
//                        )
//                        .add(R.id.container, SettingFragment())
//                        .addToBackStack(null)
//                        .commit()
//                }
//            }
//
//            reportImageView.setOnClickListener {
////                if (!sharePref.getIsMute()) betTouch.start()
//                layCfStatus.isVisible = true
//                it.btnClick().subscribe {
//                    supportFragmentManager.beginTransaction()
//                        .setCustomAnimations(
//                            R.anim.slide_in,
//                            R.anim.slide_out,
//                            R.anim.slide_in_exit,
//                            R.anim.slide_out_exit
//                        )
//                        .add(R.id.container, StatementFragment().apply {
//                            arguments =
//                                Bundle().apply {
//                                    // putInt(Fragment7.COM_INFO_ID_KEY, companyInfoId)
//                                }
//                        })
//                        .addToBackStack(null)
//                        .commit()
//                }
//            }
//        }
//    }
}
