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.ComponentCustomEditDialogBinding
import es.verdnatura.presentation.common.showKeyboard
import es.verdnatura.presentation.view.feature.main.activity.MainActivity


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

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


    init {

        setContentView(binding.root)
        //setContentView(R.layout.component_custom_edit_dialog)
    }

    fun getEditText() : TextInputEditText {

        return binding.customDialogValue
        //return custom_dialog_value
    }

    fun getValue() : String {

        return binding.customDialogValue.text.toString()
        //return custom_dialog_value.text.toString()

    }

    fun setValue(value : String): CustomDialogInput{

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

//        custom_dialog_value.setText(value)
//        custom_dialog_value.visibility = View.VISIBLE
        return this
    }

    fun setTitle(title: String): CustomDialogInput {

        binding.customDialogTitle.visibility=View.VISIBLE
        binding.customDialogTitle.text=title
//        custom_dialog_title.visibility = View.VISIBLE
//        custom_dialog_title.text = title
        return this
    }

    fun setDescription(description: String): CustomDialogInput {

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

        /*custom_dialog_description.visibility = View.VISIBLE
        custom_dialog_description.text = description*/
        return this
    }

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

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

      /*  custom_dialog_button_ok.visibility = View.VISIBLE
        custom_dialog_button_ok.text = text
        custom_dialog_button_ok.setOnClickListener { onButtonClicked() }*/
        return this
    }

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

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

        /*custom_dialog_button_ko.visibility = View.VISIBLE
        custom_dialog_button_ko.text = text
        custom_dialog_button_ko.setOnClickListener { onButtonClicked() }*/

        return this
    }

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