package com.ycgis.macall.personalcenter.v.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.rs.macall.androidx.basemodel.base.BaseRecyclerAdapter;
import com.rs.macall.androidx.basemodel.utils.StringUtil;
import com.ycgis.macall.personalcenter.R;
import com.ycgis.macall.personalcenter.databinding.ItmeFeedbackListBinding;
import com.ycgis.macall.personalcenter.m.adapterbean.FeedbackBean;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * created by:   Macall
 * create time:  2023/11/16 16:39
 * copyright:    @ruansee.com
 * Describe:
 */
public class FeedBackListAdapter extends BaseRecyclerAdapter<FeedbackBean,BaseRecyclerAdapter.ViewHolder> {

    public FeedBackListAdapter(Context context, List<FeedbackBean> dataList) {
        super(context, dataList);
    }

    @Override
    public int getItemViewType(int position) {
        return getDataItem(position).getBaseType();
    }

    @NonNull
    @NotNull
    @Override
    public BaseRecyclerAdapter.ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        if (viewType == 0 || viewType == -1) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_error_empty_xiao, parent, false);
            return new ErrorViewHolder(view);
        }
        if (viewType == 1){
            View view = bindView(parent,R.layout.itme_feedback_list);
            ItmeFeedbackListBinding binding = ItmeFeedbackListBinding.bind(view);
            return new ViewDataBindingHolder<>(binding);
        }
        return null;
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull BaseRecyclerAdapter.ViewHolder viewHolder, int position) {
        if (viewHolder instanceof ViewDataBindingHolder){
            ViewDataBindingHolder<ItmeFeedbackListBinding> holder  = (ViewDataBindingHolder<ItmeFeedbackListBinding> )viewHolder;
            FeedbackBean dataItem = getDataItem(position);
            holder.viewBind.setData(dataItem);
            if (StringUtil.isNullOrEmpty(dataItem.getApplicationName())){
                holder.viewBind.feedbackBqAppName.setVisibility(View.GONE);
            }else {
                holder.viewBind.feedbackBqAppName.setText(dataItem.getApplicationName());
            }
            if (dataItem.getReplyStatus() == 0){
                holder.viewBind.feedbackTvReply.setBackground(ContextCompat.getDrawable(context,R.drawable.bk_gray));
                holder.viewBind.feedbackTvReply.setTextColor(ContextCompat.getColor(context,R.color.colorGrey6));
            }else {
                holder.viewBind.feedbackTvReply.setBackground(ContextCompat.getDrawable(context,R.drawable.bk_ls));
                holder.viewBind.feedbackTvReply.setTextColor(ContextCompat.getColor(context,R.color.colorGreen6));
            }
        }
        if (viewHolder instanceof BaseRecyclerAdapter.ErrorViewHolder) {
            ErrorViewHolder holder = (ErrorViewHolder) viewHolder;
            if (getDataItem(position).getBaseType() == 0) {
                holder.setEmpty(getDataItem(position).getBaseMessage());
            } else {
                holder.setError(getDataItem(position).getBaseMessage());
            }
        }
    }
}
