package com.yidian.shenghuoquan.newscontent.widget

import android.content.Context
import android.util.AttributeSet
import android.view.View
import com.yidian.nightmode.widget.YdConstraintLayout
import com.yidian.shenghuoquan.newscontent.R
import com.yidian.shenghuoquan.newscontent.databinding.ViewLifeAccountAuthSelectBinding

/**
 * author: yinjiacheng
 * date: 5/28/21 2:41 PM
 * description: 生活号认证 职业标签/商户类型选择
 */
class LifeAccountAuthSelectView @JvmOverloads constructor(
  context: Context,
  attrs: AttributeSet? = null,
  defStyle: Int = 0
) : YdConstraintLayout(context, attrs, defStyle), View.OnClickListener {

  private val viewBinding = ViewLifeAccountAuthSelectBinding.bind(
    View.inflate(
      getContext(),
      R.layout.view_life_account_auth_select,
      this
    )
  )

  init {
    val typeArray =
      getContext().obtainStyledAttributes(attrs, R.styleable.LifeAccountAuthSelectView)
    viewBinding.tvName.text =
      typeArray.getString(R.styleable.LifeAccountAuthSelectView_LifeAccountAuthSelectView_name_text)
    viewBinding.tvContent.hint =
      typeArray.getString(R.styleable.LifeAccountAuthSelectView_LifeAccountAuthSelectView_content_hint_text)
    typeArray.recycle()
  }

  /**
   * 回显选择的内容
   */
  fun setContentResult(text: String) {
    viewBinding.tvContent.text = text
  }

  /**
   * 获取当前选择的内容
   */
  fun getContentResult(): String {
    return viewBinding.tvContent.text.toString()
  }

  /**
   * 设置是否能选择 即是否可以弹出选择弹窗
   * @param enable true为可选择 false为不可选择
   */
  fun enableSelect(enable: Boolean) {
    isEnabled = enable
    viewBinding.ivSelect.visibility = if (enable) View.VISIBLE else View.GONE
  }

  /**
   * 清空当前选择的内容
   */
  fun clearContentResult() {
    viewBinding.tvContent.text = ""
  }

  override fun onClick(v: View?) {

  }

  interface OnLifeAccountAuthSelectViewCallback {
    /**
     * 点击选择功能
     */
    fun onLifeAccountAuthSelect()
  }


}
