package com.zztrapp.zztrapp.ui.currency.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.SewageFacilitiesTasksBean;
import com.zztrapp.zztrapp.databinding.ItemRvSpecialTasksBinding;

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

/**
 * Describe 专项任务-污水
 * Created by Bby on 2022/6/23
 * Email bby0856@163.com
 */

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

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

    public interface OnItemClickListener {
        void onEditClick(String id);

        void onLookDetailClick(String id);
    }

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

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

    public void setData(List<SewageFacilitiesTasksBean.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) {
        if (list.get(position).getIsKfbj() == null || list.get(position).getIsKfbj() == 0) {
            holder.bindings.edit.setVisibility(View.GONE);
        } else {
            holder.bindings.edit.setVisibility(View.VISIBLE
            );
        }
        holder.bindings.taskName.setText("任务名称 " + list.get(position).getRwmc());
        List<String> arrayList = new ArrayList<>();
        arrayList.add("任务名称：" + list.get(position).getRwmc());
        arrayList.add("任务年度：" + list.get(position).getNd());
        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.edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onItemClickListener != null) {
                    onItemClickListener.onEditClick(list.get(position).getId());
                }
            }
        });
        holder.bindings.lookDetail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onItemClickListener != null) {
                    onItemClickListener.onLookDetailClick(list.get(position).getId());
                }
            }
        });
    }

    @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;
        }
    }
}