package com.yidian.shenghuoquan.newscontent.ui.dialog

import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.WindowManager
import com.yidian.bcommon.base.BaseDialog
import com.yidian.shenghuoquan.newscontent.R
import com.yidian.shenghuoquan.newscontent.databinding.DialogMerchantCenterBottomHintBinding
import com.yidian.utils.DensityUtil

/**
 * author: yinjiacheng
 * date: 6/9/21 8:56 PM
 * description: 商户管理中心底部提示弹窗
 */
class MerchantCenterBottomHintDialog(
  context: Context,
  val type: Int,
  val callback: OnMerchantCenterBottomHintCallback? = null
) :
  BaseDialog<DialogMerchantCenterBottomHintBinding>(
    context,
    R.style.merchant_center_bottom_hint_dialog
  ),
  View.OnClickListener {

  companion object {
    // 认证升级
    const val TYPE_AUTH_UPGRADE = 1

    // 认证驳回
    const val TYPE_AUTH_REJECT = 2
  }

  override fun createViewBinding(): DialogMerchantCenterBottomHintBinding {
    return DialogMerchantCenterBottomHintBinding.inflate(layoutInflater)
  }

  override fun initView() {
    when (type) {
      TYPE_AUTH_UPGRADE -> {
        viewBinding.root.setBackgroundResource(R.drawable.shape_bg_bottom_hint)
        viewBinding.tvContent.text =
          context.resources.getString(R.string.upgrade_auth)
        viewBinding.tvSubContent.text =
          context.resources.getString(R.string.auth_merchant_description)
        viewBinding.tvNext.setBackgroundResource(R.drawable.shape_bg_common_btn)
        viewBinding.tvNext.setTextColor(context.resources.getColor(R.color.color_FFFFFFFF))
        viewBinding.tvNext.text = context.resources.getString(R.string.immediate_upgrade)
      }
      TYPE_AUTH_REJECT -> {
        viewBinding.root.setBackgroundResource(R.drawable.shape_bg_bottom_warn)
        viewBinding.tvContent.text =
          context.resources.getString(R.string.auth_apply_reject)
        viewBinding.tvSubContent.text =
          context.resources.getString(R.string.apply_auth_merchant_description)
        viewBinding.tvNext.setBackgroundResource(R.drawable.shape_bg_modify_auth_btn)
        viewBinding.tvNext.setTextColor(context.resources.getColor(R.color.color_FFFF3A3A))
        viewBinding.tvNext.text = context.resources.getString(R.string.modify_auth)
      }
    }
  }

  override fun initListener() {
    viewBinding.tvNext.setOnClickListener(this)
  }

  override fun show() {
    super.show()
    window?.setGravity(Gravity.BOTTOM)
    val params = window?.attributes
    params?.width = WindowManager.LayoutParams.MATCH_PARENT
    params?.height = DensityUtil.dp2px(84f)
    window?.attributes = params
  }

  override fun onClick(v: View?) {
    if (v?.id == R.id.tv_next) {
      when (type) {
        TYPE_AUTH_UPGRADE -> {
          // 升级认证
          callback?.onUpgradeAuth()
        }
        TYPE_AUTH_REJECT -> {
          // 修改企业认证
          callback?.onModifyEnterpriseAuth()
        }
      }
    }
  }

  interface OnMerchantCenterBottomHintCallback {
    /**
     * 由未认证升级认证
     */
    fun onUpgradeAuth()

    /**
     * 修改企业认证
     */
    fun onModifyEnterpriseAuth()
  }
}
