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

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

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 com.tofly.ghrq_route.module.buildManage.domain.BuildReportBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Amu on 2017/5/22.
 */

public class BuildReportAdapter extends ARecyclerBaseAdapter<BuildReportAdapter.MyViewHolder, BuildReportBean> {

    private Context mContext;

    private List<BuildReportBean> mData;

    private BuildManageBean mBuildManage;

    public BuildReportAdapter(Context context, List<BuildReportBean> data, BuildManageBean buildManage) {
        super(context, data);
        mContext = context;
        mData = data;
        mBuildManage = buildManage;
    }

    public void setData(List<BuildReportBean> data) {
        mData = data;
        notifyDataSetChanged();
    }

    @Override
    public BuildReportBean getItem(int position) {
        BuildReportBean reportBean = null;
        if (position < mData.size()){
            reportBean = mData.get(position);
        }
        return reportBean;
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View rootView = LayoutInflater.from(mContext).inflate(R.layout.listview_build_report_item, parent, false);
        MyViewHolder viewHolder = new MyViewHolder(rootView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position) {
        BuildReportBean buildReport = getItem(position);
        if (buildReport != null) {
            /*int state = buildReport.getReport_state();
            if (state < reportStates.length){
                holder.textReportState.setText(reportStates[state]);
            }*/
            /*int state = mBuildManage.getBuild_state() + 1;
            if (state < buildStates.length) {
                holder.textReportState.setText(buildStates[state]);
            }*/
            holder.textReportTime.setText(buildReport.getReport_time());
            holder.textReportAddr.setText(buildReport.getAddress());
            holder.layoutPictureArea.setVisibility(View.GONE);
            if (onItemClickListener != null){
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        onItemClickListener.onItemClick(holder.itemView, holder.getLayoutPosition());
                    }
                });
            }
        }
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.image_report_icon)
        ImageView imageReportIcon;
        @BindView(R.id.text_report_state)
        TextView textReportState;
        @BindView(R.id.text_report_time)
        TextView textReportTime;
        @BindView(R.id.text_report_addr)
        TextView textReportAddr;
        @BindView(R.id.layout_picture_area)
        LinearLayout layoutPictureArea;
        @BindView(R.id.picture_gallery)
        LinearLayout pictureGallery;

        MyViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
