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

import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.Display
import androidx.core.hardware.display.DisplayManagerCompat
import com.nivesh.production.partnerOnBoarding.databinding.ActivityRegisterBinding
import com.nivesh.production.partnerOnBoarding.db.PreferenceManager
import com.nivesh.production.partnerOnBoarding.util.Common.Companion.showWebViewDialogBottom

class RegisterActivity : BaseActivity() {
    lateinit var binding: ActivityRegisterBinding

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

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

        binding.imgInfo.setOnClickListener {

        }

        binding.btnInvestor.setOnClickListener {
            intent = Intent(this@RegisterActivity, RegisterActivity::class.java)
            startActivity(intent)
        }

        binding.btnDistributor.setOnClickListener {
            commonMethod(4, "3")//advisory
        }

        binding.btnReferrer.setOnClickListener {
            commonMethod(3, "4")//associate
        }

        binding.imgInfo.setOnClickListener {
            showWebViewDialogBottom(
                this@RegisterActivity,
                "https://smallbusiness.chron.com/create-dummy-webpage-51199.html",
                getScreenHeight()
            )
        }
    }

    private fun commonMethod(type: Int, brokerType: String) {
        intent = if (!PreferenceManager(this@RegisterActivity).getFirstTime()){
            Intent(this@RegisterActivity, ViewPagerActivity::class.java)
        }else{
            Intent(this@RegisterActivity, SignUpActivity::class.java)
        }
        intent.putExtra("type", type)
        intent.putExtra("arnType",brokerType)
        startActivity(intent)
    }

    private fun getScreenHeight(): Int {
        val height: Int = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            val defaultDisplay = DisplayManagerCompat.getInstance(this@RegisterActivity).getDisplay(Display.DEFAULT_DISPLAY)
            val displayContext = createDisplayContext(defaultDisplay!!)
            displayContext.resources.displayMetrics.heightPixels
        } else {
            val displayMetrics = DisplayMetrics()
            @Suppress("DEPRECATION")
            windowManager.defaultDisplay.getMetrics(displayMetrics)
            displayMetrics.heightPixels
        }
        return height
    }
}