package com.nivesh.production.partnerOnBoarding.ui.activities

import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.viewpager.widget.ViewPager
import com.nivesh.production.partnerOnBoarding.databinding.ActivityViewpagerBinding
import com.nivesh.production.partnerOnBoarding.db.PreferenceManager
import com.nivesh.production.partnerOnBoarding.ui.fragments.StepTwoPagerFragment
import com.nivesh.production.partnerOnBoarding.adapters.DisableAdapter1
import com.nivesh.production.partnerOnBoarding.adapters.SectionsPagerAdapter1
import com.nivesh.production.partnerOnBoarding.ui.fragments.StepOnePagerFragment
import com.nivesh.production.partnerOnBoarding.ui.fragments.StepThreePagerFragment

class ViewPagerActivity : BaseActivity() {
    lateinit var binding: ActivityViewpagerBinding
    private lateinit var fragments: Array<Fragment>
    private lateinit var sectionsPagerAdapter: SectionsPagerAdapter1
    private val stepOnePagerFragment = StepOnePagerFragment()
    private val stepTwoPagerFragment = StepTwoPagerFragment()
    private val stepThreePagerFragment = StepThreePagerFragment()
    var type : Int? = null
    private var brokerType: String? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        init()
    }

    private fun init() {
        binding = ActivityViewpagerBinding.inflate(layoutInflater)
        binding.apply {
            setContentView(this.root)
        }
        setViewPager()
    }

    private fun setViewPager() {

        PreferenceManager(this@ViewPagerActivity).setIsFirstTime(true)
        type = intent.getIntExtra("type", 0)
        brokerType = intent.getStringExtra("arnType")

        fragments = arrayOf(
            stepOnePagerFragment,
            stepTwoPagerFragment,
            stepThreePagerFragment
        )

        sectionsPagerAdapter = SectionsPagerAdapter1(supportFragmentManager, fragments)
        val viewPager: DisableAdapter1 = binding.viewPager1
        viewPager.adapter = sectionsPagerAdapter
        viewPager.setPagingEnabled(false)
        viewPager.offscreenPageLimit = 3
        binding.tabDots.setupWithViewPager(viewPager)
        viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {
            }

            override fun onPageSelected(position: Int) {
                when (position) {
                    0 -> {

                    }
                    1 -> {

                    }
                    2 -> {

                    }
                }
            }

            override fun onPageScrollStateChanged(state: Int) {

            }
        })

        binding.tvSkip.setOnClickListener{
            stepFourApi()
        }
    }

    // step 1 response
    fun stepOneApi() {
        binding.viewPager1.currentItem = 0
    }

    // step 2 response
    fun stepTwoApi() {
        binding.viewPager1.currentItem = 1
    }

    // step 3 response
    fun stepThreeApi() {
        binding.viewPager1.currentItem = 2
    }

    // step 4 response
    fun stepFourApi() {
        intent = Intent(this@ViewPagerActivity, SignUpActivity::class.java)
        intent.putExtra("type", type)
        intent.putExtra("arnType",brokerType)
        startActivity(intent)
    }

}