package com.abbidot.tracker.deprecated.ui.fragment.profile

import android.content.Context
import android.os.Bundle
import android.view.View
import com.abbidot.tracker.R
import com.abbidot.tracker.base.BaseFragment
import com.abbidot.tracker.databinding.FragmentPaymentSuccessBinding
import com.abbidot.tracker.deprecated.ui.activity.profile.recharge.PaymentResultActivity

/**
 * 支付成功
 */
class PaymentSuccessFragment :
    BaseFragment<FragmentPaymentSuccessBinding>(FragmentPaymentSuccessBinding::inflate) {

    companion object {
        @JvmStatic
        fun newInstance(context: Context) = PaymentSuccessFragment().apply {
            mContext = context
        }
    }

    override fun initData() {
        setOnClickListenerViews(mViewBinding.btnPaymentSuccessBack)
        mViewBinding.paymentSuccessLottieAnimation.setAnimation("lottie/success_anim.json")

        val activity = mActivity as PaymentResultActivity
        activity.apply {
            if (mAmount > 0) {
                val amount = String.format(getString(R.string.txt_dollar), mAmount)
                mViewBinding.paymentSuccessMoneyText.text = amount
            } else {
                mViewBinding.paymentSuccessMoneyText.visibility = View.GONE
            }
        }
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        mViewBinding.root.setBackgroundResource(R.color.transparent)
        mViewBinding.paymentSuccessLottieAnimation.playAnimation()
    }

    override fun onDestroy() {
        super.onDestroy()
        mViewBinding.paymentSuccessLottieAnimation.cancelAnimation()
    }


    override fun onClick(v: View?) {
        when (v!!) {
            mViewBinding.btnPaymentSuccessBack -> {
                val activity = mActivity as PaymentResultActivity
                activity.leftBackOnClick()
            }
        }
    }
}