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.BfjPageListBean;
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 BfjPagelistAdapter extends RecyclerView.Adapter<BfjPagelistAdapter.ItemHolder> {

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

    public interface OnItemClickListener {
        void onRecordClick(String id, int position);

        void onLookDetailClick(String id, int position);
    }

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

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

    public void setData(List<BfjPageListBean.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).getFqjbh());
        List<String> arrayList = new ArrayList<>();
        arrayList.add("废弃井名称：" + list.get(position).getMc());
        //状态 0 为回填1、已回填
        switch (list.get(position).getZt()) {
            case 0:
                arrayList.add("是否回填：否");
                break;
            case 1:
                arrayList.add("是否回填：是");
                holder.bindings.record.setVisibility(View.VISIBLE);
                break;
        }
        arrayList.add("经度：" + list.get(position).getJd());
        arrayList.add("纬度：" + list.get(position).getWd());
        holder.bindings.rv.setLayoutManager(new FlexboxLayoutManager(mContext));
        FlexBoxItemAdapter adapter = new FlexBoxItemAdapter(mContext);
        holder.bindings.rv.setAdapter(adapter);
        adapter.setData(arrayList);


        holder.bindings.record.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onItemClickListener != null) {
                    onItemClickListener.onRecordClick(list.get(position).getId(), position);
                }
            }
        });
        holder.bindings.lookDetail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onItemClickListener != null) {
                    onItemClickListener.onLookDetailClick(list.get(position).getId(), 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;
        }
    }
}