package com.nivesh.production.niveshfd.partnerOnBoarding.ui.activities1

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.niveshfd.databinding.ActivityRegisterBinding
import com.nivesh.production.niveshfd.fd.db.PreferenceManager
import com.nivesh.production.niveshfd.fd.ui.activity.BaseActivity
import com.nivesh.production.niveshfd.fd.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 {
            if (!PreferenceManager(this@RegisterActivity).getFirstTime()){
                intent = Intent(this@RegisterActivity, ViewPagerActivity::class.java)
                intent.putExtra("type", 4)
                startActivity(intent)
            }else{
                intent = Intent(this@RegisterActivity, SignUpActivity::class.java)
                intent.putExtra("type", 4)
                startActivity(intent)
            }
        }
        binding.btnReferrer.setOnClickListener {
            if (!PreferenceManager(this@RegisterActivity).getFirstTime()){
                intent = Intent(this@RegisterActivity, ViewPagerActivity::class.java)
                intent.putExtra("type", 3)
                startActivity(intent)
            }else{
                intent = Intent(this@RegisterActivity, SignUpActivity::class.java)
                intent.putExtra("type", 3)
                startActivity(intent)
            }
        }
        binding.imgInfo.setOnClickListener {
            showWebViewDialogBottom(
                this@RegisterActivity,
                "https://smallbusiness.chron.com/create-dummy-webpage-51199.html",
                getScreenHeight()
            )
        }
    }

    private fun getScreenHeight(): Int {
        val height: Int = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            val defaultDisplay =
                DisplayManagerCompat.getInstance(this).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
    }
}