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 com.rs.macall.androidx.basemodel.base.BaseRecyclerAdapter;
import com.ycgis.macall.personalcenter.R;
import com.ycgis.macall.personalcenter.databinding.ItemTravelCityBinding;
import com.ycgis.macall.personalcenter.m.adapterbean.TravelCityBean;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * created by:   Macall
 * create time:  2023/11/13 10:32
 * copyright:    @ruansee.com
 * Describe:
 */
public class TravelAssistantAdapter  extends BaseRecyclerAdapter<TravelCityBean,BaseRecyclerAdapter.ViewHolder> {

    public TravelAssistantAdapter(Context context, List<TravelCityBean> 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.item_travel_city);
            ItemTravelCityBinding binding = ItemTravelCityBinding.bind(view);
            return new ViewBindingHolder<>(binding);
        }
        return null;
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull BaseRecyclerAdapter.ViewHolder viewHolder, int position) {
        if (viewHolder instanceof ViewBindingHolder){
            ViewBindingHolder<ItemTravelCityBinding> holder = (ViewBindingHolder<ItemTravelCityBinding>)viewHolder;
            holder.viewBind.travelTvCityName.setText(getDataItem(position).getName());
        }
        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());
            }
        }
    }
}
