package com.bonait.bnframework.common.linktab.makegood;

import android.content.res.Resources;
import android.view.View;

import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.bonait.bnframework.R;
import com.bonait.bnframework.common.db.QueryDB;
import com.bonait.bnframework.common.linktab.LinkMode;
import com.bonait.bnframework.common.model.mode.GoodsTypeInfo;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import java.util.List;

public class MakeGoodLeftAdapter extends BaseQuickAdapter<LinkMode, BaseViewHolder> {
    public List<LinkMode> Fdata;
    public Resources resources;
    public LinearLayoutManager Manager;

    public MakeGoodLeftAdapter(@LayoutRes int layoutResId, @Nullable List<LinkMode> data, Resources _resources, LinearLayoutManager _manager) {
        super(layoutResId, data);
        resources = _resources;
        Fdata = data;
        Manager = _manager;
    }

    @Override
    protected void convert(BaseViewHolder holder, LinkMode item) {

        GoodsTypeInfo type = (GoodsTypeInfo) item.type;
        holder.setText(R.id.tv_type, type.goodsType_Name);
        int index_d = Fdata.indexOf(item);
        if (item.isChoose) {
            holder.setBackgroundColor(R.id.tv_linearlayout, resources.getColor(R.color.tab_11));
            holder.setTextColor(R.id.tv_type, resources.getColor(R.color.topbj1));
            holder.setVisible(R.id.tv_image, true);
        } else {
            holder.setBackgroundColor(R.id.tv_linearlayout, resources.getColor(R.color.transparent));
            holder.setTextColor(R.id.tv_type, resources.getColor(R.color.tab_text_normal));
            holder.setVisible(R.id.tv_image, false);
        }

        //选中行
        holder.getView(R.id.tv_type_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setChoose(index_d);
                Manager.scrollToPositionWithOffset(index_d, 0);
            }
        });
    }

    /**
     * 设置是否选择
     *
     * @param position
     */
    public void setChoose(Integer position) {
        for (LinkMode it : Fdata) {
            it.isChoose = false;
        }

        if(position<Fdata.size())
        {
            Fdata.get(position).isChoose = true;
        }
        notifyDataSetChanged();
    }
}

