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.HeiChouShuiTiIndexBean;
import com.zztrapp.zztrapp.databinding.ItemRvSpecialTasksBinding;
import com.zztrapp.zztrapp.ui.currency.adapter.FlexBoxItemAdapter;
import com.zztrapp.zztrapp.utilcode.klogs.KLog;

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

/**
 * Describe 黑臭水体-首页
 * Created by Bby on 2022/6/23
 * Email bby0856@163.com
 */

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

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

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

        void onLookDetailClick(String id, int position);

        void onDailyTasksClick(String id);
    }

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

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

    public void setData(List<HeiChouShuiTiIndexBean.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.dailyTasks.setVisibility(View.VISIBLE);
        holder.bindings.taskName.setText("水体名称 " + list.get(position).getStmc());
        List<String> arrayList = new ArrayList<>();
        arrayList.add("水体编号：" + list.get(position).getStbh());
        arrayList.add("行政区划：" + list.get(position).getCountyName());
        arrayList.add("起点经度：" + list.get(position).getHcdqdjd());
        arrayList.add("终点经度：" + list.get(position).getHcdzdjd());
        arrayList.add("起点纬度：" + list.get(position).getHcdqdwd());
        arrayList.add("终点纬度：" + list.get(position).getHcdzdwd());
        arrayList.add("终点纬度：" + list.get(position).getHcdzdwd());
        switch (list.get(position).getAqzt()) {//安全状态0、黑臭水体 1、正常水体 默认0
            case 0:
                arrayList.add("状态：安全");
                break;
            case 1:
                arrayList.add("状态：黑臭水体");
                break;
            case 2:
                arrayList.add("状态：正常水体");
                break;
        }
        String isFfst = list.get(position).getIsFfst() == 1 ? "是" : "否";
        arrayList.add("是否反复水体：" + isFfst);

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