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.buildManage.domain.BuildManageBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author YCHK
 * 历史记录适配器
 */
public class BuildHistoryAdapter extends ARecyclerBaseAdapter<BuildHistoryAdapter.MyViewHolder, BuildManageBean> {

    private Context context;
    private List<BuildManageBean> data;

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

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

    @NonNull
    @Override
    public 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 BuildManageBean news = data.get(position);
        if (!TextUtils.isEmpty(news.getSiteName())) {
            holder.textBuildName.setText(news.getSiteName());
        }
        if (!TextUtils.isEmpty(news.getSiteType())) {
            if (news.getSiteType().equals("0")) {
                holder.textProjectType.setText("第三方施工");
            } else if (news.getSiteType().equals("1")) {
                holder.textProjectType.setText("自建工程");
            }
        }
        if (!TextUtils.isEmpty(news.getConstructionAddress())) {
            holder.textBuildAddr.setText(news.getConstructionAddress());
        }
        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_build_time)
        TextView textBuildTime;
        @BindView(R.id.text_project_type)
        TextView textProjectType;
        @BindView(R.id.text_build_state)
        TextView textBuildState;
        @BindView(R.id.text_log_time)
        TextView textLogTime;
        @BindView(R.id.text_build_addr)
        TextView textBuildAddr;
        @BindView(R.id.text_build_report_enroll)
        TextView textBuildReportEnroll;
        @BindView(R.id.text_build_handle)
        TextView textBuildHandle;

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