export const ResetPasswordFragment = (configuration) => {
  return `
    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 ${configuration.name}.R
    import ${configuration.packageName}.data.local.AppPreferences
    import ${configuration.name}.databinding.FragmentResetPasswordBinding
    import ${configuration.packageName}.extensions.setOnClickWithDebounce
    import ${configuration.packageName}.extensions.snackBar
    import ${configuration.packageName}.extensions.viewBinding
    import ${configuration.packageName}.network.Status
    import ${configuration.packageName}.viewmodels.BaasViewModel
    import ${configuration.packageName}.extensions.hideSoftKeyboard
    import org.koin.android.ext.android.inject
    import org.koin.androidx.viewmodel.ext.android.viewModel
    import android.widget.VideoView
    import androidx.activity.result.contract.ActivityResultContracts
    import com.manaknight.app.extensions.viewBinding
    import android.provider.MediaStore
    import android.widget.Toast
    import androidx.appcompat.app.AppCompatActivity



class ResetPasswordFragment : Fragment(R.layout.fragment_reset_password) {

    private val binding by viewBinding(FragmentResetPasswordBinding::bind)
    private val baasViewModel: BaasViewModel by viewModel()
    var code = ""
    var password = ""


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

        val codeFields = arrayOf(
            binding.code1, binding.code2, binding.code3,
            binding.code4, binding.code5, binding.code6
        )

        codeFields.forEachIndexed { index, editText ->
            editText.doAfterTextChanged {
                val stringBuilder = StringBuilder(code)
                if (it.toString().isEmpty() && stringBuilder.toString().length > 0) {
                    code = stringBuilder.deleteAt(index).toString()
                } else {
                    val stringBuilder = StringBuilder(code)
                    code = stringBuilder.apply { insert(index, it.toString()) }.toString()
                }
                if (it.toString().isNotEmpty()) {
                    // If the entered character is not empty, move focus to the next field
                    if (index < codeFields.size - 1) {
                        codeFields[index + 1].requestFocus()
                    }
                }
            }
        }

        // binding.code1.doAfterTextChanged { code += it.toString() }
        // binding.code2.doAfterTextChanged { code += it.toString() }
        // binding.code3.doAfterTextChanged { code += it.toString() }
        // binding.code4.doAfterTextChanged { code += it.toString() }
        // binding.code5.doAfterTextChanged { code += it.toString() }
        // binding.code6.doAfterTextChanged { code += it.toString() }

        binding.newPassword.doAfterTextChanged { password = it.toString() }
      

        binding.submitButton.setOnClickListener {

            if (code.length != 6 || password.isEmpty()) {
                Toast.makeText(context, "Please fill all fields.", Toast.LENGTH_SHORT).show();
            } else {
                requireActivity().hideSoftKeyboard()
                baasViewModel.resetPasswordMobile(code, password).observe(viewLifecycleOwner) {
                    when (it.status) {
                        Status.ERROR -> snackBar(it.message ?: getString(R.string.something_went_wrong))
                        Status.LOADING -> {
                            snackBar("loading")
                        }

                        Status.SUCCESS -> {
                            snackBar("success")
                           findNavController().navigate(R.id.loginFragment)
                        }
                    }
                }
            }
        }

    }
      override fun onResume() {
            super.onResume()
            // (activity as AppCompatActivity?)!!.supportActionBar!!.hide()
        }

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

}
    `;
};
