package com.tanya.careerguidanceproject.activities

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import androidx.appcompat.widget.Toolbar
import com.tanya.careerguidanceproject.DBHandler
import com.tanya.careerguidanceproject.R

class RegistrationActivity : AppCompatActivity() {

    private lateinit var toolbar : Toolbar
    private lateinit var btnRegister : Button
    private lateinit var etName : EditText
    private lateinit var etEmailId : EditText
    private lateinit var etMobileNumber : EditText
    private lateinit var etPassword : EditText
    private var dbHandler: DBHandler? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_registration)

        btnRegister = findViewById(R.id.btnRegister)
        etName = findViewById(R.id.etNameRegister)
        etEmailId = findViewById(R.id.etEmailRegister)
        etMobileNumber = findViewById(R.id.etMobileNumberRegister)
        etPassword = findViewById(R.id.etSetPasswordRegister)

        /*toolbar = findViewById(R.id.toolbarRegister)
        setUpToolbar()*/

        dbHandler = DBHandler(this@RegistrationActivity)

        /*btnRegister.setOnClickListener {

            Toast.makeText(this@RegistrationActivity,
                    "Register button clicked",
                    Toast.LENGTH_LONG
            ).show()

            val intent = Intent(this@RegistrationActivity, LoginActivity::class.java)
            startActivity(intent)
        }*/

        btnRegister.setOnClickListener { // below line is to get data from all edit text fields.
            val userName = etName.text.toString()
            val userEmailId = etEmailId.text.toString()
            val userMobileNumber = etMobileNumber.text.toString()
            val userPassword = etPassword.text.toString()

            if (userName.isEmpty() && userEmailId.isEmpty() && userMobileNumber.isEmpty() && userPassword.isEmpty()) {
                Toast.makeText(
                    this@RegistrationActivity,
                    "Please enter all the data..",
                    Toast.LENGTH_SHORT
                ).show()
            }

            dbHandler!!.addNewUser(userName, userEmailId, userMobileNumber, userPassword)

            val intent = Intent(this@RegistrationActivity, LoginActivity::class.java)
            startActivity(intent)

        }
    }

    /*private fun setUpToolbar(){
        setSupportActionBar(toolbar)
        supportActionBar?.title = "Register"
        supportActionBar?.setHomeButtonEnabled(true)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
    }*/
}