package com.tofly.ghrq_route.common.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

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

import com.lcp.arecyclerview.widget.ARecyclerBaseAdapter;
import com.tofly.ghrq_route.R;
import com.tofly.ghrq_route.module.rushrepair.domain.RushRepairBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class RushRepairHistoryAdapter extends ARecyclerBaseAdapter<RushRepairHistoryAdapter.MyViewHolder, RushRepairBean> {

    private Context context;
    private List<RushRepairBean> data;

    public RushRepairHistoryAdapter(Context mContext, List<RushRepairBean> mList) {
        super(mContext, mList);
        this.context = mContext;
        this.data = mList;
    }

    public void setData(List<RushRepairBean> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public RushRepairHistoryAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_history, parent, false);
        MyViewHolder viewHolder = new MyViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        final RushRepairBean news = data.get(position);
        if (!TextUtils.isEmpty(news.getWorkOrderId())) {
            holder.textBuildName.setText("工单编号" + news.getWorkOrderId());
        }
        if (!TextUtils.isEmpty(news.getWorkOrderTypeName())) {
            holder.textProjectType.setText(news.getWorkOrderTypeName());
        }
        if (!TextUtils.isEmpty(news.getAddress())) {
            holder.textBuildAddr.setText(news.getAddress());
        }
        if (onItemClickListener != null) {
            holder.itemView.setOnClickListener(v -> onItemClickListener.onItemClick(holder.itemView, holder.getLayoutPosition()));
        }
    }

    static class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.image_build_icon)
        ImageView imageBuildIcon;
        @BindView(R.id.text_build_name)
        TextView textBuildName;
        @BindView(R.id.text_project_type)
        TextView textProjectType;
        @BindView(R.id.text_build_addr)
        TextView textBuildAddr;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
