package com.yidian.shenghuoquan.bmanagercenter.widget

import android.content.Context
import android.util.AttributeSet
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import com.yidian.shenghuoquan.bmanagercenter.R
import com.yidian.shenghuoquan.bmanagercenter.databinding.ViewMerchantAssetBinding

/**
 * author: yinjiacheng
 * date: 6/8/21 10:58 PM
 * description: 商户资产
 */
class MerchantAssetView @JvmOverloads constructor(
  context: Context,
  attrs: AttributeSet? = null,
  defStyle: Int = 0
) : ConstraintLayout(context, attrs, defStyle), View.OnClickListener {

  private var callback: OnClickWalletCallback? = null

  private val viewBinding = ViewMerchantAssetBinding.bind(
    View.inflate(
      getContext(),
      R.layout.view_merchant_asset,
      this
    )
  )

  init {
    viewBinding.tvWalletBalance.setOnClickListener(this)
    viewBinding.tvToWalletBalance.setOnClickListener(this)
  }

  /**
   * 数据填充
   * @param income 当月收入
   * @param balance 钱包yue
   */
  fun setMerchantAssetData(income: String, balance: String) {
    viewBinding.tvMonthlyIncome.text = income
    viewBinding.tvWalletBalance.text = balance
  }

  override fun onClick(v: View?) {
    when (v?.id) {
      R.id.tv_wallet_balance -> {
        // 进入钱包
        callback?.toMyWallet(viewBinding.tvWalletBalance.text.toString())
      }
    }
  }

  fun setOnClickWalletCallback(callback: OnClickWalletCallback) {
    this.callback = callback
  }

  interface OnClickWalletCallback {
    fun toMyWallet(balance: String)
  }

}
