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

import android.content.Context;
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.ycgis.macall.personalcenter.R;
import com.ycgis.macall.personalcenter.databinding.ItemApplyForMainButtonBinding;
import com.ycgis.macall.personalcenter.m.adapterbean.ActionBean;
import com.ycgis.macall.personalcenter.m.adapterbean.BaseBean;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * created by:   Macall
 * create time:  2023/5/31 10:52
 * copyright:    @ruansee.com
 * Describe:
 */
public class ApplyForMainAdapter extends BaseRecyclerAdapter<BaseBean,BaseRecyclerAdapter.ViewHolder> {
    public ApplyForMainAdapter(Context context, List<BaseBean> 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 == 1){
           View view = bindView(parent, R.layout.item_apply_for_main_button);
           ItemApplyForMainButtonBinding buttonBinding = ItemApplyForMainButtonBinding.bind(view);
           return new ViewBindingHolder<>(buttonBinding);
       }
        if (viewType == 0||viewType == -1){
            View view = bindView(parent, R.layout.item_error);
            return new ErrorViewHolder(view);
        }
        return null;
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull BaseRecyclerAdapter.ViewHolder viewHolder, int position) {
        if (viewHolder instanceof ViewBindingHolder){
            ViewBindingHolder holder  =(ViewBindingHolder) viewHolder;
            if (holder.viewBind instanceof ItemApplyForMainButtonBinding){
                ItemApplyForMainButtonBinding binding = (ItemApplyForMainButtonBinding) holder.viewBind;
                ActionBean bean  = (ActionBean) getDataItem(position);
                binding.ivIcon.setImageDrawable(ContextCompat.getDrawable(context,bean.getIconId()));
                binding.tvName.setText(bean.getName());
            }
        }
        if (viewHolder instanceof BaseRecyclerAdapter.ErrorViewHolder){
            ErrorViewHolder holder = (ErrorViewHolder) viewHolder;
            BaseBean dataItem = getDataItem(position);
            if (dataItem.getBaseType() == 0){
                holder.setEmpty(dataItem.getBaseMessage());
            }else {
                holder.setError(dataItem.getBaseMessage());
            }
        }
    }



}
