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.FragmentPaymentFailBinding
import com.abbidot.tracker.deprecated.ui.activity.profile.recharge.PaymentResultActivity

/**
 * 支付失败
 */
class PaymentFailFragment :
    BaseFragment<FragmentPaymentFailBinding>(FragmentPaymentFailBinding::inflate) {

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

    override fun initData() {
        setOnClickListenerViews(mViewBinding.paymentFailAgain, mViewBinding.paymentFailBack)
        mViewBinding.paymentFailLottieAnimation.setAnimation("lottie/fail_anim.json")
    }

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

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

    override fun onClick(v: View?) {
        when (v!!) {
            mViewBinding.paymentFailAgain -> {
                finish(mActivity!!)
            }

            mViewBinding.paymentFailBack -> {
                val activity = mActivity as PaymentResultActivity
                activity.leftBackOnClick()
            }
        }
    }
}