package com.wdkl.ncs.android.component.home.adapter

import android.view.ViewGroup
import com.alibaba.android.vlayout.LayoutHelper
import com.alibaba.android.vlayout.VirtualLayoutManager
import com.alibaba.android.vlayout.layout.LinearLayoutHelper
import com.wdkl.ncs.android.component.home.R
import com.wdkl.ncs.android.component.home.agreement.FloorActionAgreement
import com.wdkl.ncs.android.component.home.databinding.FloorItemLtwoRoneImageLayBinding
import com.wdkl.ncs.android.component.home.databinding.FloorItemSingleImageLayBinding
import com.wdkl.ncs.android.lib.adapter.BaseDelegateAdapter
import com.wdkl.ncs.android.lib.utils.BaseRecyclerViewHolder
import com.wdkl.ncs.android.lib.utils.dpToPx
import com.wdkl.ncs.android.lib.utils.then
import com.wdkl.ncs.android.middleware.model.FloorItem
import com.wdkl.ncs.android.middleware.model.FloorViewModel
import com.enation.javashop.imagepluin.utils.GlideUtils
import com.enation.javashop.utils.base.tool.ScreenTool
import jp.wasabeef.glide.transformations.RoundedCornersTransformation

/**
 * 单个图片item
 */
class FloorRightOneLeftTwoAdapter(val data : FloorViewModel,val agreement: FloorActionAgreement) :BaseDelegateAdapter<BaseRecyclerViewHolder<FloorItemLtwoRoneImageLayBinding>,FloorItem>() {

    /**
     * @author LDD
     * @From   SingleImageAdapter
     * @Date   2018/8/16 下午5:26
     * @Note   数据提供者
     */
    override fun dataProvider(): Any {
        return data
    }


    override fun getItemViewType(position: Int): Int {
        return 8
    }


    /**
     * @author LDD
     * @From   SingleImageAdapter
     * @Date   2018/8/16 下午5:27
     * @Note   item过滤
     * @param  position Item坐标
     */
    override fun itemFilter(position: Int): Boolean {
        return true
    }

    /**
     * @author LDD
     * @From   SingleImageAdapter
     * @Date   2018/8/16 下午5:27
     * @Note   创建ViewHolder
     */
    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): BaseRecyclerViewHolder<FloorItemLtwoRoneImageLayBinding> {
        return BaseRecyclerViewHolder.build(parent,R.layout.floor_item_ltwo_rone_image_lay)
    }

    /**
     * @author LDD
     * @From   SingleImageAdapter
     * @Date   2018/8/16 下午5:27
     * @Note   获取Item总数
     */
    override fun getItemCount(): Int {
        return 1
    }

    /**
     * @author LDD
     * @From   SingleImageAdapter
     * @Date   2018/8/16 下午5:28
     * @Note   创建LayoutHelper
     */
    override fun onCreateLayoutHelper(): LayoutHelper {
        return LinearLayoutHelper(0,1).then { self ->
            self.setMargin(5.dpToPx(),0,5.dpToPx(),5.dpToPx())
        }
    }

    override fun onBindViewHolder(holder: BaseRecyclerViewHolder<FloorItemLtwoRoneImageLayBinding>?, position: Int) {
        holder?.itemView?.layoutParams = VirtualLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (ScreenTool.getScreenWidth(holder?.databinding?.root?.context!!)*0.5).toInt())
        holder?.bind { self ->
            loadImageRound(data.itemList[0].getImageValue(),self.imageA,RoundedCornersTransformation.CornerType.TOP_LEFT)
            loadImageRound(data.itemList[1].getImageValue(),self.imageB,RoundedCornersTransformation.CornerType.BOTTOM_LEFT)
            loadImageRound(data.itemList[2].getImageValue(),self.imageC,RoundedCornersTransformation.CornerType.RIGHT)
            agreement.floorHandle(self.imageA,data.itemList[0])
            agreement.floorHandle(self.imageB,data.itemList[1])
            agreement.floorHandle(self.imageC,data.itemList[2])
        }
    }
}