package es.verdnatura.presentation.view.component

import android.app.Dialog
import android.content.Context
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.textfield.TextInputEditText
import es.verdnatura.R
import es.verdnatura.databinding.ComponentCustomListDialogBinding
//import kotlinx.android.synthetic.main.component_custom_list_dialog.*


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


    private var binding: ComponentCustomListDialogBinding = ComponentCustomListDialogBinding.inflate(layoutInflater)
    init {

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

    fun getRecyclerView() : RecyclerView {

        return binding.itemRecyclerview
        //return item_recyclerview
    }

    fun getEditText() : TextInputEditText {
        return binding.customDialogValue
        //return custom_dialog_value
    }

    fun getEditTextTwo() : TextInputEditText {
        return binding.customDialogValueTwo
        //return custom_dialog_value_two
    }

    fun getValue() : String {
        return binding.customDialogValue.text.toString()
        //return custom_dialog_value.text.toString()
    }

    fun setValue(value : String): CustomDialogList{
        binding.customDialogValue.setText(value)
        binding.textinputlayoutUsername.visibility=View.VISIBLE
        /*custom_dialog_value.setText(value)
        textinputlayout_username.visibility = View.VISIBLE*/
        return this
    }

    fun getValueTwo() : String {
        return binding.customDialogValueTwo.text.toString()
        //return custom_dialog_value_two.text.toString()
    }

    fun setValueTwo(value : String): CustomDialogList{
        binding.customDialogValueTwo.setText(value)
        binding.textinputlayoutTwo.visibility=View.VISIBLE

       /* custom_dialog_value_two.setText(value)
        textinputlayout_two.visibility = View.VISIBLE*/
        return this
    }

    fun setTitle(title: String): CustomDialogList {
       binding.customDialogTitle.visibility=View.VISIBLE
        binding.customDialogTitle.text=title
     /*   custom_dialog_title.visibility = View.VISIBLE
        custom_dialog_title.text = title*/
        return this
    }

    fun setDescription(title: String): CustomDialogList {
        binding.customDialogDescription.visibility=View.VISIBLE
        binding.customDialogDescription.text=title

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


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

        binding.customDialogButtonOk.visibility=View.VISIBLE
        binding.customDialogButtonOk.text=text

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

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

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

    fun setHintValue(text:String): CustomDialogList{

        binding.customDialogValue.hint=text
//        custom_dialog_value.hint = text
        return this
    }

    fun setHintValueTwo(text:String): CustomDialogList{
        binding.customDialogValueTwo.hint=text
        //custom_dialog_value_two.hint = text
        return this
    }

    fun setTextTwoGone():CustomDialogList{
        binding.textinputlayoutTwo.visibility = View.GONE
        //textinputlayout_two.visibility = View.GONE
        return this
    }

    fun hideDialog():CustomDialogList{
        binding.customDialogValue.visibility = View.GONE
        //custom_dialog_value.visibility = View.GONE
        return this
    }

}