package com.hongyegroup.cpt_rewards.ui

import android.content.Intent
import android.os.Bundle
import com.guadou.lib_baselib.base.activity.BaseVDBActivity
import com.guadou.lib_baselib.bean.DataBindingConfig
import com.guadou.lib_baselib.ext.horizontal
import com.guadou.lib_baselib.ext.vertical
import com.guadou.lib_baselib.utils.CommUtils
import com.hongyegroup.cpt_rewards.BR
import com.hongyegroup.cpt_rewards.R
import com.hongyegroup.cpt_rewards.databinding.ActivityRewardsBinding
import com.hongyegroup.cpt_rewards.mvvm.RewardsViewModel

class RewardsActivity : BaseVDBActivity<RewardsViewModel, ActivityRewardsBinding>() {

    val mClickProxy by lazy { ClickProxy() }

    companion object {

        fun startInstance() {
            val context = CommUtils.getContext()
            val intent = Intent(context, RewardsActivity::class.java)
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            context.startActivity(intent)
        }

    }

    override fun init(savedInstanceState: Bundle?) {

        initView()
        initListener()

    }

    private fun initListener() {

        mViewModel.mRecommendAdapter.setOnItemClickListener{ adapter, view, position ->

            mClickProxy.gotoRewardsDetail()

        }


    }

    private fun initView() {

        //分类
        for (index in 0..8) {

            mViewModel.mCategoryDatas.add("")

        }
        mBinding.recyclerViewPromotionRewardsCategory.horizontal().adapter = mViewModel.mCategoryAdapter
        mViewModel.mCategoryAdapter.notifyDataSetChanged()

        //Recommend
        for (index in 0..8) {

            mViewModel.mRecommendDatas.add("")

        }

        mBinding.recyclerViewPromotionRewardsRecommend.horizontal().adapter = mViewModel.mRecommendAdapter
        mViewModel.mRecommendAdapter.notifyDataSetChanged()

        //Hottest
        for (index in 0..8) {

            mViewModel.mHottestDatas.add("")

        }

        mBinding.recyclerViewPromotionRewardsHottest.horizontal().adapter = mViewModel.mHottestAdapter
        mViewModel.mHottestAdapter.notifyDataSetChanged()

        //Food & Beverage
        for (index in 0..8) {

            mViewModel.mFoodBeverageDatas.add("")

        }

        mBinding.recyclerViewPromotionRewardsFood.horizontal().adapter = mViewModel.mFoodBeverageAdapter
        mViewModel.mFoodBeverageAdapter.notifyDataSetChanged()

        //Best Offer
        for (index in 0..8) {

            mViewModel.mBestOfferDatas.add("")

        }

        mBinding.recyclerViewPromotionRewardsOffers.vertical().adapter = mViewModel.mBestOfferAdapter
        mViewModel.mBestOfferAdapter.notifyDataSetChanged()


    }

    override fun getDataBindingConfig(): DataBindingConfig {

        return DataBindingConfig(R.layout.activity_rewards, BR.viewModel, mViewModel)
            .addBindingParams(BR.click,mClickProxy)

    }

    override fun startObserve() {

    }

    /**
     * DataBinding事件处理
     */
    inner class ClickProxy {

        //跳转到搜索界面
        fun gotoSearchActivity(){

            RewardsSearchActivity.startInstance()

        }

        //查看Rewards列表
        fun gotoRewardsList(){

            RewardsListActivity.startInstance()

        }

        //跳转到Rewards详情
        fun gotoRewardsDetail(){

            RewardsDetailActivity.startInstance()

        }

        //跳转到My Rewards界面
        fun gotoMyRewardsActivity(){

            MyRewardsActivity.startInstance()

        }

    }
}