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

import android.content.res.Resources;
import android.text.InputType;
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.db.mode.BPA_GOODSTYPE;
import com.bonait.bnframework.common.linktab.LinkMode;
import com.bonait.bnframework.common.utils.AlertDialogUtils;
import com.bonait.bnframework.common.utils.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction;

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) {

        BPA_GOODSTYPE type = (BPA_GOODSTYPE) item.type;
        holder.setText(R.id.tv_type, type.name);
        int index_d = Fdata.indexOf(item);
        if (item.isChoose) {
            holder.setBackgroundColor(R.id.tv_linearlayout, resources.getColor(R.color.app_color_blue7f));
            holder.setTextColor(R.id.tv_type, resources.getColor(R.color.white));
            holder.setVisible(R.id.tv_image, true);
        } else {
            holder.setBackgroundColor(R.id.tv_linearlayout, resources.getColor(R.color.white));
            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);
                if(callBack!=null){
                    callBack.onClickItem(view,type);
                }
                if(Manager!=null){
                    Manager.scrollToPositionWithOffset(index_d, 0);
                }
            }
        });
    }

    /**
     * 删除数据
     *
     * @param index
     */
    public void Detele(int index) {
        QueryDB.DeleteGoodsType((BPA_GOODSTYPE) Fdata.get(index).type);
        Fdata.remove(index);
        notifyDataSetChanged();
    }

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

    public void setCallBack(ClickCallBack callBack) {
        this.callBack = callBack;
    }

    public interface ClickCallBack{
       void onClickItem(View v,BPA_GOODSTYPE type);
    }
}

