package com.zxbw.modulemain.fragment

import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.zxbw.modulemain.R
import com.zxbw.modulemain.adapter.GoodsListAdapter
import com.zxbw.modulemain.adapter.JgqQyAdapter
import com.zxbw.modulemain.adapter.ZeroBuyGoodsListAdapter
import com.zxbw.modulemain.contract.HomeRecommendContract
import com.zxbw.modulemain.presenter.HomeRecommendPresenter
import com.zxhl.cms.common.base.BaseFragment
import com.zxhl.cms.net.model.qy.JgqQyEntity
import com.zxhl.cms.utils.JumpUtils
import com.zxhl.cms.utils.OnRecycleItemClickListener
import kotlinx.android.synthetic.main.fragment_layout_recommend.*

/**
 * @author (wangXuewei)
 * @datetime 2022-05-20 19:01 GMT+8
 * @detail : 首页推荐
 */
class RecommendFragment : BaseFragment, HomeRecommendContract.View {

    private val title: String
    private var mPresenter: HomeRecommendPresenter? = null
    private var mJgqQyAdapter: JgqQyAdapter? = null;
    private var mZeroBuyAdapter: ZeroBuyGoodsListAdapter? = null;
    private var mGoodsAdapter: GoodsListAdapter? = null;

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

    override fun init(view: View?) {
        mPresenter = HomeRecommendPresenter(this)

        mJgqQyAdapter = JgqQyAdapter(activity,
            OnRecycleItemClickListener<JgqQyEntity> { view, position, data ->
                JumpUtils.RightsDetailJump(data.brand, "")
            })

        mZeroBuyAdapter = ZeroBuyGoodsListAdapter(activity,
            OnRecycleItemClickListener<Any> { view, position, data ->
                showToast("零元购")
            })
        mGoodsAdapter = GoodsListAdapter(activity,
            OnRecycleItemClickListener<Any> { view, position, data ->
                showToast("postion" + position)
            })
        //金刚区权益
        val gridLayoutManager = GridLayoutManager(activity, 3)
        gridLayoutManager.orientation = LinearLayoutManager.HORIZONTAL
        id_rcl_jgq_qy_list?.layoutManager = gridLayoutManager
        id_rcl_jgq_qy_list.adapter = mJgqQyAdapter
        //零元购
        id_rcl_zero_buy_goods?.layoutManager = GridLayoutManager(activity, 3)
        id_rcl_zero_buy_goods.adapter = mZeroBuyAdapter
        //底部商品列表
        id_rcl_goods_list?.layoutManager = LinearLayoutManager(activity)
        id_rcl_goods_list.adapter = mGoodsAdapter

        mPresenter?.getQyCardList()
    }

    companion object {
        fun newInstance(string: String): RecommendFragment {
            return RecommendFragment(string)
        }
    }

    constructor(title: String) : super() {
        this.title = title
    }

    constructor() : super() {
        this.title = ""
    }

    override fun setQyCardList(result: List<JgqQyEntity>) {
        mJgqQyAdapter?.clear()
        mJgqQyAdapter?.appendToList(result)
    }

}