package com.bonait.bnframework.modules.home.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.bonait.bnframework.R;
import com.bonait.bnframework.common.constant.DataBus;
import com.bonait.bnframework.common.db.QueryDB;
import com.bonait.bnframework.common.db.mode.BPA_GOODPROPERTY;
import com.bonait.bnframework.common.db.res.ResGoodProperty;
import com.bonait.bnframework.common.db.res.ResGoodsMake;
import com.bonait.bnframework.common.helper.I.MyClickListener;
import com.bonait.bnframework.common.utils.AlertDialogUtils;
import com.bonait.bnframework.common.view.MyLayoutManager;
import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction;

import java.util.ArrayList;
import java.util.List;

public class pfsx_adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private ArrayList<ResGoodProperty> datas= new ArrayList<>();
    int resource1;
    public Context contextA;
    private final LayoutInflater mLayoutInflater;
//    private List<String> idList = new ArrayList<>();
//    private String goodId="";
//    public void setGoodId(String goodId) {
//        this.goodId = goodId;
//    }
//
//    public void setIdList(List<String> idList) {
//        this.idList = idList;
//    }

    public pfsx_adapter(Context context, ArrayList<ResGoodProperty> ac) {
        this.contextA = context;
        datas=ac;
        mLayoutInflater = LayoutInflater.from(context);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = mLayoutInflater.inflate(R.layout.pfsx_item, parent, false);
        return new MyViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
        if (holder instanceof MyViewHolder) {
            MyViewHolder myViewHolder = (MyViewHolder) holder;
            ResGoodProperty bpa_goodproperty =datas.get(position);

            if(position == datas.size()-1){
                myViewHolder.root.setBackgroundResource(0);
            }else {
                myViewHolder.root.setBackgroundResource(R.drawable.input_bj);
            }
            MyLayoutManager layout = new MyLayoutManager();
            layout.setAutoMeasureEnabled(true);
            myViewHolder.recyclerView.setLayoutManager(layout);
            newpropertyselect_adapter zsxadapter = new newpropertyselect_adapter(contextA,bpa_goodproperty.child);
            zsxadapter.setClickCallBack(new newpropertyselect_adapter.ItemClickCallBack() {
                @Override
                public void onClickItem(View view, int pos, String attributeId) {
                    if(clickCallBack!=null){
                        clickCallBack.onClickItem(view,position,attributeId);
                    }
                }
            });
//            zsxadapter.setIdList(idList);
//            zsxadapter.setGoodId(goodId);
            myViewHolder.recyclerView.setAdapter(zsxadapter);

            // 设置要显示的图片和文字
            myViewHolder.name.setText(bpa_goodproperty.name+":");
        }
    }
    @Override
    public int getItemCount() {
        return datas.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder {
        RecyclerView recyclerView;
        TextView name;
        RelativeLayout root;
        public MyViewHolder(View view) {
            super(view);
            recyclerView = view.findViewById(R.id.recycler_view);
            name = view.findViewById(R.id.name);
            root = view.findViewById(R.id.root);
        }
    }

    private ItemClickCallBack clickCallBack;

    public void setClickCallBack(ItemClickCallBack clickCallBack) {
        this.clickCallBack = clickCallBack;
    }

    public interface ItemClickCallBack{
        /**
         *
         * @param view
         * @param position 父属性位置
         * @param attributeId 子属性id
         */
        void onClickItem(View view,int position,String attributeId);
    }

}
