package com.zxhl.cms.pay.view

import android.content.Intent
import android.view.View
import com.zxhl.cms.R
import com.zxhl.cms.common.base.BaseActivity
import com.zxhl.cms.net.model.box.AppInEntity
import com.zxhl.cms.pay.contract.PaymentPageContract
import com.zxhl.cms.widget.CenterDialog
import kotlinx.android.synthetic.main.activity_layout_payment_page.*
import kotlinx.android.synthetic.main.activity_layout_payment_page.id_img_back
import kotlinx.android.synthetic.main.activity_member.*

/**
 * @author (wangXuewei)
 * @datetime 2022-04-13 15:56 GMT+8
 * @detail :
 */
class PaymentPageActivity : BaseActivity(), PaymentPageContract.View {

    companion object {
        const val GOOGLE_PAY = 4  //Google支付类型
        const val PAY_PAL_PAY = 5  //PayPal支付类型
    }

    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
        init()
    }

    private var payType: Int? = GOOGLE_PAY

    override fun init() {
        val goodsType = intent?.data?.getQueryParameter("pay_goods_type") ?: ""
        val goodsId = intent?.data?.getQueryParameter("pay_goods_id") ?: ""
        val goodsName = intent?.data?.getQueryParameter("pay_goods_name") ?: ""
        val goodsPrice = intent?.data?.getQueryParameter("pay_goods_price") ?: ""

        id_tv_goods_name.text = goodsName
        id_tv_goods_price.text = "Price:$${goodsPrice}"
        id_tv_pay_btn.text = "Pay $${goodsPrice}"

        id_img_back.setOnClickListener(this)
        id_img_google_btn.setOnClickListener(this)
        id_rl_paypal_pay.setOnClickListener(this)
        id_tv_pay_btn.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        when (v) {
            id_img_back -> {
                finish()
            }
            id_img_google_btn -> {
                selectPayType(GOOGLE_PAY)
            }
            id_rl_paypal_pay -> {
                selectPayType(PAY_PAL_PAY)
            }
            id_tv_pay_btn -> {
                CenterDialog.showPaySuccessDialog(this)
            }
        }
    }

    override fun layoutID(): Int {
        return R.layout.activity_layout_payment_page
    }

    private fun selectPayType(type: Int) {
        payType = type
        id_img_google_btn?.setImageResource(R.drawable.icon_check_weixuanzhong)
        id_img_paypal_btn?.setImageResource(R.drawable.icon_check_weixuanzhong)
        when (type) {
            GOOGLE_PAY -> {
                id_img_google_btn.setImageResource(R.drawable.icon_check_xuanzhong)
            }
            PAY_PAL_PAY -> {
                id_img_paypal_btn.setImageResource(R.drawable.icon_check_xuanzhong)
            }
        }
    }

    override fun orderVerificationSuccessful(status: String) {

    }

    override fun orderVerificationFailed(errorMsg: String) {

    }

    override fun setAppInfo(result: AppInEntity?) {

    }

}