package es.verdnatura.presentation.view.component

import android.app.Dialog
import android.content.Context
import android.text.InputType
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.textfield.TextInputEditText
import es.verdnatura.R
import es.verdnatura.databinding.ComponentCustomEditDialogBinding
import es.verdnatura.databinding.ComponentCustomEditDialogNotesBinding


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

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


    init {

        setContentView(binding.root)
    }

    fun getEditText(): TextInputEditText {

        return binding.customDialogValue
    }

    fun getValue(): String {

        return binding.customDialogValue.text.toString()

    }

    fun setValue(value: String): CustomDialogInputNotes {

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

        return this
    }

    fun setTitle(title: String): CustomDialogInputNotes {

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

        return this
    }

    fun setDescription(description: String): CustomDialogInputNotes {

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

        return this
    }

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

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

        return this
    }

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

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

        return this
    }

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

    fun setFocusText() {
        binding.customDialogValue.requestFocus()
    }
    fun getRecyclerView() : RecyclerView {
        return binding.recyclerItems
    }
}