package com.casic.br.fragment.shop

import com.bumptech.glide.Glide
import com.casic.br.R
import com.casic.br.adapter.FavoriteAdapter
import com.casic.br.adapter.FeaturedGoodsAdapter
import com.casic.br.model.BannerImageModel
import com.casic.br.model.FavoriteModel
import com.casic.br.model.FeaturedGoodsModel
import com.casic.br.utils.GridItemDecoration
import com.pengxh.kt.lite.base.KotlinBaseFragment
import com.pengxh.kt.lite.extensions.show
import com.youth.banner.Banner
import com.youth.banner.adapter.BannerImageAdapter
import com.youth.banner.holder.BannerImageHolder
import com.youth.banner.indicator.RectangleIndicator
import com.youth.banner.transformer.*
import kotlinx.android.synthetic.main.fragment_favorite.*
import java.util.*

class FavoriteFragment : KotlinBaseFragment() {

    override fun initLayoutView(): Int = R.layout.fragment_favorite

    override fun setupTopBarLayout() {

    }

    override fun initData() {
        //TODO 模拟数据
        val imageModels = ArrayList<BannerImageModel>()
        for (i in 0..4) {
            val model = BannerImageModel()
            model.imageTitle = "测试轮播图"
            model.imageLink = "https://img95.699pic.com/photo/40006/1412.jpg_wh860.jpg"

            imageModels.add(model)
        }

        val banner = shopBannerView
                as Banner<BannerImageModel, BannerImageAdapter<BannerImageModel>>
        banner.apply {
            setAdapter(object : BannerImageAdapter<BannerImageModel>(imageModels) {
                override fun onBindView(
                    holder: BannerImageHolder, data: BannerImageModel, position: Int, size: Int
                ) {
                    Glide.with(holder.itemView)
                        .load(data.imageLink)
                        .placeholder(R.mipmap.load_image_error)
                        .into(holder.imageView)
                }
            })
            indicator = RectangleIndicator(requireContext())
            addPageTransformer(AlphaPageTransformer())
            addBannerLifecycleObserver(this@FavoriteFragment)

            //Banner点击事件
            setOnBannerListener { imageModel, _ ->
                "${imageModel.imageTitle}被点击了".show(requireContext())
            }
        }

        //TODO 模拟数据
        val goodsModels = ArrayList<FeaturedGoodsModel>()
        for (i in 0..5) {
            val model = FeaturedGoodsModel()
            model.deviceName = "******热水器"
            model.deviceDesc = "描述文字"

            goodsModels.add(model)
        }
        val featuredGoodsAdapter = FeaturedGoodsAdapter(requireContext(), goodsModels)
        goodsRecyclerView.addItemDecoration(GridItemDecoration(requireContext()))
        goodsRecyclerView.adapter = featuredGoodsAdapter
        featuredGoodsAdapter.setOnGridItemClickListener(object :
            FeaturedGoodsAdapter.OnGridItemClickListener {
            override fun onItemClick(position: Int) {

            }
        })

        //TODO 模拟数据
        val favoriteModels = ArrayList<FavoriteModel>()
        for (i in 0..5) {
            val model = FavoriteModel()
            model.deviceName = "智能厨房*****"
            model.deviceDesc = "描述文字"

            favoriteModels.add(model)
        }
        val favoriteAdapter = FavoriteAdapter(requireContext(), favoriteModels)
        favoriteGridView.addItemDecoration(GridItemDecoration(requireContext()))
        favoriteGridView.adapter = favoriteAdapter
        favoriteAdapter.setOnGridItemClickListener(object :
            FavoriteAdapter.OnGridItemClickListener {
            override fun onItemClick(position: Int) {

            }
        })
    }

    override fun observeRequestState() {

    }

    override fun initEvent() {

    }
}