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.ItemTravelCityListBinding;
import com.ycgis.macall.personalcenter.m.adapterbean.TravelCityBean;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * created by:   Macall
 * create time:  2023/11/14 9:28
 * copyright:    @ruansee.com
 * Describe:
 */
public class TravelSearchListAdapter extends BaseRecyclerAdapter<TravelCityBean,BaseRecyclerAdapter.ViewHolder> {


    public TravelSearchListAdapter(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 == 1){
            View view = bindView(parent, R.layout.item_travel_city_list);
            ItemTravelCityListBinding bind = ItemTravelCityListBinding.bind(view);
            return new ViewBindingHolder<>(bind);
        }
        if (viewType == 0 || viewType == -1) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_error_empty_xiao, parent, false);
            return new ErrorViewHolder(view);
        }
        return null;
    }

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