package com.tofly.ghrq_route.module.trouble.ui.adapter;

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

import androidx.recyclerview.widget.RecyclerView;

import com.gaoyuan.weixinrecord.example.Record;
import com.lcp.arecyclerview.widget.ARecyclerBaseAdapter;
import com.tofly.ghrq_route.R;
import com.tofly.ghrq_route.module.trouble.domain.AuditEndBean;
import com.tofly.ghrq_route.module.trouble.domain.TroubleBean;
import com.tofly.ghrq_route.common.util.file.FileViewUtil;

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

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Amu on 2017/1/10.
 */

public class TroubleExecuteReportAdapter extends ARecyclerBaseAdapter<TroubleExecuteReportAdapter.ViewHolder, AuditEndBean> {
    private Context context;

    private FileViewUtil fileViewUtil;

    private List<Record> mRecords;

    private TroubleBean mTroubleBean;

    public TroubleExecuteReportAdapter(Context context, TroubleBean troubleBean, List<AuditEndBean> featureList) {
        super(context, featureList);
        this.context = context;
        mTroubleBean = troubleBean;
        fileViewUtil = new FileViewUtil(context);
        mRecords = new ArrayList<>();
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_trouble_scheme_verify, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.setData(position);
    }

    protected class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.text_scheme_title)
        TextView textSchemeTitle;
        @BindView(R.id.text_duty_name)
        TextView textDutyName;
        @BindView(R.id.layout_handler_name)
        LinearLayout layoutHandlerName;
        @BindView(R.id.text_assists_name)
        TextView textAssistsName;
        @BindView(R.id.text_scheme_time)
        TextView textSchemeTime;
        @BindView(R.id.layout_scheme_note)
        LinearLayout layoutSchemeNote;
        @BindView(R.id.text_scheme_note)
        TextView textSchemeNote;
        @BindView(R.id.layout_scheme_module)
        LinearLayout layoutSchemeModule;
        @BindView(R.id.btn_verify)
        Button btnVerify;
        @BindView(R.id.layout_action)
        LinearLayout layoutAction;
        @BindView(R.id.text_verify_user)
        TextView textVerifyUser;
        @BindView(R.id.text_check_time)
        TextView textCheckTime;
        @BindView(R.id.text_verify_state)
        TextView textVerifyState;
        @BindView(R.id.layout_verify_note)
        LinearLayout layoutVerifyNote;
        @BindView(R.id.text_verify_note)
        TextView textVerifyNote;
        @BindView(R.id.layout_check_report_module)
        LinearLayout layoutCheckReportModule;

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

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

        public void setData(final int position) {
            layoutHandlerName.setVisibility(View.GONE);
            AuditEndBean auditEndBean = getItem(position);
            if (auditEndBean != null) {
                textSchemeTitle.setText("回报" + (position+1));
                String handleTime = auditEndBean.getHandleTime();
                if (handleTime != null)
                    textSchemeTime.setText(handleTime);

                String dutyUserName = mTroubleBean.getDutyUserName();
                if (dutyUserName != null && !dutyUserName.isEmpty()) {
                    textDutyName.setText(dutyUserName);
                }

                layoutSchemeNote.setVisibility(View.GONE);
                String handleNote = auditEndBean.getHandleNote();
                if (handleNote != null && !handleNote.isEmpty()) {
                    layoutSchemeNote.setVisibility(View.VISIBLE);
                    textSchemeNote.setText(handleNote);
                }

                String auditMindName = auditEndBean.getAuditMindName();
                if (auditMindName == null) {
                    layoutAction.setVisibility(View.GONE);
                    layoutCheckReportModule.setVisibility(View.GONE);
                } else {
                    layoutAction.setVisibility(View.GONE);
                    layoutCheckReportModule.setVisibility(View.VISIBLE);

                    textVerifyUser.setText(auditEndBean.getAuditorUndersecretaryName());
                    String auditTime = auditEndBean.getAuditTime();
                    if (auditTime != null)
                        textCheckTime.setText(auditTime);

                    layoutVerifyNote.setVisibility(View.GONE);
                    String description = auditEndBean.getAuditDescription();
                    if (description != null && !description.isEmpty()) {
                        layoutVerifyNote.setVisibility(View.VISIBLE);
                        textVerifyNote.setText(description);
                    }

                    textVerifyState.setText(auditMindName);
                }
            }
        }

    }
}
