package es.verdnatura.presentation.view.component

import android.app.Dialog
import android.content.Context
import android.text.InputType
import android.view.View
import com.google.android.material.textfield.TextInputEditText
import es.verdnatura.R
import es.verdnatura.databinding.ComponentCustomEditDialogTwoValuesBinding


class CustomDialogInputTwoValues(context: Context) : Dialog(context, R.style.DialogTheme) {

    private var binding: ComponentCustomEditDialogTwoValuesBinding =
        ComponentCustomEditDialogTwoValuesBinding.inflate(layoutInflater)


    init {

        setContentView(binding.root)
        setInputText()
        setInputTextTwoVisibility()
        setFocusTextTwo()
    }

    fun getEditText(): TextInputEditText {

        return binding.customDialogValue


    }

    fun getEditTextTwo(): TextInputEditText {

        return binding.customDialogValueTwo

    }

    fun getValue(): String {

        return binding.customDialogValue.text.toString()


    }

    fun getValueTwo(): String {

        return binding.customDialogValueTwo.text.toString()

    }

    fun setValue(value: String): CustomDialogInputTwoValues {

        binding.customDialogValue.setText(value)
        binding.customDialogValue.visibility = View.VISIBLE


        return this
    }
    fun setValueTwo(value: String): CustomDialogInputTwoValues {

        binding.customDialogValueTwo.setText(value)
        binding.customDialogValue.visibility = View.VISIBLE


        return this
    }
    fun setEnableValue(isEnabled: Boolean): CustomDialogInputTwoValues {

        binding.customDialogValue.isEnabled=isEnabled


        return this
    }
    fun setTitle(title: String): CustomDialogInputTwoValues {

        binding.customDialogTitle.visibility = View.VISIBLE
        binding.customDialogTitle.text = title

        return this
    }

    fun setDescription(description: String): CustomDialogInputTwoValues {

        binding.customDialogDescription.visibility = View.VISIBLE
        binding.customDialogDescription.text = description


        return this
    }

    fun setOkButton(text: String, onButtonClicked: () -> Unit): CustomDialogInputTwoValues {

        binding.customDialogButtonOk.visibility = View.VISIBLE
        binding.customDialogButtonOk.text = text
        binding.customDialogButtonOk.setOnClickListener { onButtonClicked() }

        return this
    }

    fun setKoButton(text: String, onButtonClicked: () -> Unit): CustomDialogInputTwoValues {

        binding.customDialogButtonKo.visibility = View.VISIBLE
        binding.customDialogButtonKo.text = text
        binding.customDialogButtonKo.setOnClickListener { onButtonClicked() }


        return this
    }

    fun setInputText() {
        binding.customDialogValue.inputType = InputType.TYPE_CLASS_NUMBER
    }

    fun setInputTextTwo() {
        binding.customDialogValueTwo.inputType = InputType.TYPE_CLASS_NUMBER
    }
    fun setInfoTex(text:String){
        binding.textinputlayoutUsername.hint = text
    }

    fun setInfoTextTwo(text:String){
        binding.textinputlayoutTwo.hint = text
    }


    fun setInputTextTwoVisibility() {
        binding.textinputlayoutTwo.visibility = View.VISIBLE
    }
    fun setInputTextVisibility(visibility:Int) {
        binding.textinputlayoutTwo.visibility = visibility
    }

    fun setFocusText() {
        binding.customDialogValue.requestFocus()
    }

    fun setFocusTextTwo() {
        binding.customDialogValueTwo.requestFocus()
    }

}