package com.zxhl.cms.pay.view

import android.util.Log
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.PagerSnapHelper
import androidx.recyclerview.widget.RecyclerView
import com.zxhl.cms.R
import com.zxhl.cms.common.Constant
import com.zxhl.cms.common.base.BaseActivity
import com.zxhl.cms.net.model.pay.CoinStoreEntity
import com.zxhl.cms.net.model.pay.VipPayEntity
import com.zxhl.cms.pay.adapter.BecomeVipBannerAdapter
import com.zxhl.cms.pay.adapter.BecomeVipPriceAdapter
import com.zxhl.cms.pay.contract.VipPayContract
import com.zxhl.cms.pay.presenter.VipPayPresenter
import com.zxhl.cms.utils.JumpUtils
import com.zxhl.cms.utils.OnRecycleItemClickListener
import com.zxhl.cms.widget.CenterDialog
import com.zxhl.cms.widget.RecyclerViewPageChangeListenerHelper
import kotlinx.android.synthetic.main.activity_layout_vip_pay.*


class VipPayActivity : BaseActivity(), VipPayContract.View,
    OnRecycleItemClickListener<VipPayEntity> {
    private var mBannerAdapter: BecomeVipBannerAdapter? = null
    private var mPriceAdapter: BecomeVipPriceAdapter? = null
    private var mPresenter: VipPayPresenter? = null
    override fun init() {

        mPresenter = VipPayPresenter(this)

        mBannerAdapter = BecomeVipBannerAdapter(this)
        mPriceAdapter = BecomeVipPriceAdapter(this, this)

        vipBannerInit()

        id_rcl_pay_vip_list?.layoutManager = LinearLayoutManager(this)
        id_rcl_pay_vip_list?.adapter = mPriceAdapter

        mPresenter?.getVipPayList()
        mPriceAdapter?.setSelectView(0)

        id_img_back.setOnClickListener(this)
        id_img_vip_record.setOnClickListener(this)
        id_tv_vip_pay_btn.setOnClickListener(this)
    }

    private fun vipBannerInit() {
        id_rcl_banner?.layoutManager = LinearLayoutManager(
            this,
            LinearLayoutManager.HORIZONTAL,
            false
        )
        id_rcl_banner?.adapter = mBannerAdapter

        val mPagerSnapHelper = PagerSnapHelper()
        mPagerSnapHelper.attachToRecyclerView(id_rcl_banner)
        id_rcl_banner.addOnScrollListener(
            RecyclerViewPageChangeListenerHelper(mPagerSnapHelper,
                object : RecyclerViewPageChangeListenerHelper.OnPageChangeListener {
                    override fun onScrollStateChanged(recyclerView: RecyclerView?, newState: Int) {

                    }

                    override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) {

                    }

                    override fun onPageSelected(position: Int) {
                        Log.d("wxw", "pos${position}")
                    }
                })
        )

    }

    override fun onClick(v: View?) {
        when (v) {
            id_img_vip_record -> {
                showToast("VIP Pay Record")
            }
            id_tv_vip_pay_btn -> {
                showToast("VIP Pay ")
                JumpUtils.paymentPageJump(Constant.Key.PAY_TYPE_VIP,"1","vip","9.9")
            }
            id_img_back -> {
                CenterDialog.showPayExitDialog(this) {
                    finish()
                }
            }
        }
    }

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

    override fun setVipPayList(result: List<CoinStoreEntity>?) {

    }

    override fun onItemClick(view: View?, position: Int, data: VipPayEntity?) {
        mPriceAdapter?.setSelectView(position)
    }

    override fun onBackPressed() {
        CenterDialog.showPayExitDialog(this) {
            finish()
        }
    }
}