package com.pan_american.android.util

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import android.widget.ProgressBar
import android.widget.TextView
import com.pan_american.android.R

class CommitButton(context: Context, attrs: AttributeSet?) : LinearLayout(context, attrs) {

    private val view: View

    private val commitButton: LinearLayout

    private val commitText: TextView

    private val commitLoading: ProgressBar

    private var buttonStatus = 0

    init {
        view = LayoutInflater.from(context).inflate(R.layout.layout_commit_button, this)
        commitButton = view.findViewById(R.id.commit_button)
        commitText = view.findViewById(R.id.commit_text)
        commitLoading = view.findViewById(R.id.commit_loading)
    }

    fun setText(text: String) {
        commitText.text = text
    }

//    fun setTextSize(textSize: Int) {
//        commitText.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize.toFloat())
//    }
//
//    fun setTextStyle(style: Typeface) {
//        commitText.typeface = style
//    }

    fun setButtonStatus(type: Int) {
        when(type) {
            1 -> {

                if (buttonStatus == 0) {
                    commitText.visibility = View.GONE

                    commitLoading.visibility = View.VISIBLE

                    commitButton.isEnabled = false
                }

            }

            0 -> {

                if (buttonStatus == 1) {
                    commitText.visibility = View.VISIBLE

                    commitLoading.visibility = View.GONE

                    commitButton.isEnabled = true
                }

            }
        }

        buttonStatus = type
    }
}