export const SignUpFragment = (configuration) =>
  `
package ${configuration.packageName}.ui.fragments

import android.os.Bundle
import android.view.View
import androidx.core.widget.doAfterTextChanged
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import android.widget.Toast
import ${configuration.name}.R
import ${configuration.name}.databinding.FragmentSignUpBinding
import ${configuration.packageName}.extensions.checkIsEmpty
import ${configuration.packageName}.extensions.disableSpaces
import ${configuration.packageName}.extensions.hide
import ${configuration.packageName}.extensions.hideSoftKeyboard
import ${configuration.packageName}.extensions.setOnClickWithDebounce
import ${configuration.packageName}.extensions.show
import ${configuration.packageName}.extensions.snackBar
import ${configuration.packageName}.extensions.textToString
import ${configuration.packageName}.extensions.viewBinding
import ${configuration.packageName}.network.Status
import ${configuration.packageName}.viewmodels.BaasViewModel
import org.koin.androidx.viewmodel.ext.android.viewModel
import androidx.appcompat.app.AppCompatActivity

class SignUpFragment : Fragment(R.layout.fragment_sign_up) {

    private val binding by viewBinding(FragmentSignUpBinding::bind)
    private val baasViewModel: BaasViewModel by viewModel()
    private var fullName = ""
    private var email = ""
    private var password = ""

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        binding.ivBack.setOnClickWithDebounce {
            findNavController().popBackStack()
        }

        binding.btnSignin.setOnClickWithDebounce {
            findNavController().popBackStack()
        }

        binding.btnCreateAccount.setOnClickWithDebounce {
            validate()
        }

        binding.edTxtName.doAfterTextChanged { fullName = it.toString() }
        binding.edtEmail.doAfterTextChanged { email = it.toString() }
        binding.edtPass.doAfterTextChanged { password = it.toString() }
        binding.edtEmail.disableSpaces()
        binding.edtPass.disableSpaces()

    }

    private fun register(email: String, password: String, name: String) {
        val words = name.trim().split("\\\\s+".toRegex()).toTypedArray()
        requireActivity().hideSoftKeyboard()
       
        baasViewModel.registerLambda(email, "user", true, true, password, words.first(), words.last(), "", "")
            .observe(viewLifecycleOwner) {
                when (it.status) {
                    Status.ERROR -> snackBar(it.message ?: getString(R.string.something_went_wrong))
                    Status.LOADING -> {
                        snackBar("Please wait...")
                    }

                    Status.SUCCESS -> {
                        findNavController().popBackStack()
                    }
                }
            }
    }

    private fun validate() {
        with(binding) {

            if(binding.edTxtUsername.text!!.isEmpty()) {
                Toast.makeText(context, "Please enter username", Toast.LENGTH_SHORT).show();
            } else if(fullName.isEmpty()) {
                Toast.makeText(context, "Please enter full name", Toast.LENGTH_SHORT).show();
            } else {


                if (email.isEmpty()) {
                    tvInvalid.show()
                    return
                }
                tvInvalid.hide()
                if (password.checkIsEmpty() || password.length < 6) {
                    tvNotMatch.show()
                    tvNotMatch.text = getString(R.string.invalid_password)
                    return
                }
                tvNotMatch.hide()
                

                register(email, password, name = fullName)
            }
        }
    }
  override fun onResume() {
            super.onResume()
            (activity as AppCompatActivity?)?.supportActionBar?.hide()
        }

        override fun onStop() {
            super.onStop()
            (activity as AppCompatActivity?)?.supportActionBar?.show()
        }

}
    
`;
