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.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.lcp.arecyclerview.widget.ARecyclerBaseAdapter;
import com.tofly.ghrq_route.R;
import com.tofly.ghrq_route.module.planPointRepair.domain.PlanPointRepair;
import com.tofly.ghrq_route.module.trouble.domain.TroubleBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

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

public class ChildRepairHistoryAdapter extends ARecyclerBaseAdapter<ChildRepairHistoryAdapter.MyViewHolder, PlanPointRepair> {
    private int mDeviceTypeId = 0;

    public ChildRepairHistoryAdapter(Context context, List<PlanPointRepair> data) {
        super(context, data);
    }

    public void setDeviceTypeId(int typeId){
        mDeviceTypeId = typeId;
    }

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

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position) {
        PlanPointRepair pointRepair = getItem(position);
        if (pointRepair != null) {
            holder.textSubmitTime.setText(pointRepair.getCreate_time());
            holder.textRepairNote.setText(pointRepair.getNotes());
            holder.textUploadState.setVisibility(View.GONE);
            if (pointRepair.getState() == TroubleBean.SAVED_STATE) {
                holder.textUploadState.setText(R.string.unUpload);
                holder.textUploadState.setVisibility(View.VISIBLE);
            }else if (pointRepair.getState() == TroubleBean.SERVER_UPDATE_UNUPLOAD_STATE) {
                holder.textUploadState.setText(R.string.updated_unUpload);
                holder.textUploadState.setVisibility(View.VISIBLE);
            }

            if (onItemClickListener != null) {
                holder.itemView.setOnClickListener(v -> onItemClickListener.onItemClick(holder.itemView, holder.getLayoutPosition()));
            }
        }
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.image_build_icon)
        ImageView imageBuildIcon;
        @BindView(R.id.text_repair_note)
        TextView textRepairNote;
        @BindView(R.id.text_upload_state)
        TextView textUploadState;
        @BindView(R.id.text_submit_time)
        TextView textSubmitTime;

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