package com.zztrapp.zztrapp.ui.index.adapter;


import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

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

import com.google.android.flexbox.FlexboxLayoutManager;
import com.zztrapp.zztrapp.bean.WrdkPageListBean;
import com.zztrapp.zztrapp.databinding.ItemRvSpecialTasksBinding;
import com.zztrapp.zztrapp.ui.currency.adapter.FlexBoxItemAdapter;

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

/**
 * Describe 污染地块分页查询
 * Created by Bby on 2022/6/27
 * Email bby0856@163.com
 */

public class WrdkPagelistAdapter extends RecyclerView.Adapter<WrdkPagelistAdapter.ItemHolder> {

    private Context mContext;
    private OnItemClickListener onItemClickListener;
    private List<WrdkPageListBean.RecordsBean> list;

    public interface OnItemClickListener {
        void onLookDetailClick(int position);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public WrdkPagelistAdapter(Context context) {
        this.mContext = context;
    }

    public void setData(List<WrdkPageListBean.RecordsBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemRvSpecialTasksBinding binding = ItemRvSpecialTasksBinding.inflate(LayoutInflater.from(mContext), parent, false);
        return new ItemHolder(binding);
    }

    @Override
    public void onBindViewHolder(ItemHolder holder, @SuppressLint("RecyclerView") int position) {
        holder.bindings.edit.setVisibility(View.GONE);
        holder.bindings.taskName.setText("地块编码 " + list.get(position).getWrdkbm());
        List<String> arrayList = new ArrayList<>();
        arrayList.add("经度：" + list.get(position).getWrdkzxjd());
        arrayList.add("纬度：" + list.get(position).getWrdkzxwd());
        //查询污染地块是否超标专用 -2 全部, -1 未确定, 0 未超标, 1 超标,
        if (null == list.get(position).getPollueted()) {
            arrayList.add("地块状态：未超标");
        } else {
            switch (list.get(position).getPollueted()) {
                case -1:
                    arrayList.add("地块状态：未确定");
                    break;
                case 1:
                    arrayList.add("地块状态：超标");
                    break;
                case 0:
                    arrayList.add("地块状态：未超标");
                    break;
            }
        }

        holder.bindings.rv.setLayoutManager(new FlexboxLayoutManager(mContext));
        FlexBoxItemAdapter adapter = new FlexBoxItemAdapter(mContext);
        holder.bindings.rv.setAdapter(adapter);
        adapter.setData(arrayList);

        holder.bindings.lookDetail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onItemClickListener != null) {
                    onItemClickListener.onLookDetailClick(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return list != null ? list.size() : 0;
    }

    static class ItemHolder extends RecyclerView.ViewHolder {
        private ItemRvSpecialTasksBinding bindings;

        public ItemHolder(ItemRvSpecialTasksBinding binding) {
            super(binding.getRoot());
            bindings = binding;
        }
    }
}