package com.ama.core.architecture.util.state

import android.view.View
import android.widget.TextView
import androidx.core.view.isVisible
import com.ama.core.architecture.R
import com.ama.core.architecture.util.toErrorMessage
import com.gamedog.vididin.core.designsystem.stateview.state.interfaces.StateErrorView


class DefaultStateErrorView : ConstraintLayoutMergeStateBaseView(), StateErrorView {
    private val errorGroup by lazy { root!!.findViewById<View>(R.id.state_error_group) }
    private val errorRetry by lazy { root!!.findViewById<View>(R.id.state_error_retry) }
    private val errorDescription by lazy { root!!.findViewById<TextView>(R.id.state_error_description) }

    override fun getResId() = R.layout.view_state_error

    override fun setVisible(isVisible: Boolean) {
        errorGroup.isVisible = isVisible
    }

    override fun onError(error: Throwable, retry: View.OnClickListener?) {
        errorRetry.setOnClickListener(retry)
        errorDescription.text = error.toErrorMessage()
    }
}