package com.rehome.meetingbook.adapter;

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

import com.rehome.meetingbook.R;
import com.rehome.meetingbook.bean.AppointmentMemberBean;
import com.rehome.meetingbook.databinding.AdapterAppointmentMemberBinding;
import com.rehome.meetingbook.databinding.AdapterAppointmentResultBinding;

import java.util.List;

/**
 * Create By HuangWenFei
 * 创建日期：2022-12-10 15:06
 * 描述：预约成员适配器
 */
public class AppointmentMemberAdapter  extends MyAdapter<AdapterAppointmentMemberBinding>{

    private List<AppointmentMemberBean.RowsBean> datas;
    private final Context context;
    private DeleteItemListener deleteItemListener;

    public AppointmentMemberAdapter(Context context, List<AppointmentMemberBean.RowsBean> datas,DeleteItemListener deleteItemListener) {
        super(context);
        this.datas = datas;
        this.context=context;
        this.deleteItemListener=deleteItemListener;
    }

    @Override
    protected void handleData(int position, AdapterAppointmentMemberBinding binding) {

        AppointmentMemberBean.RowsBean bean = (AppointmentMemberBean.RowsBean) getItem(position);

        if ((position + 1) % 2 == 0) {
            binding.ll.setBackgroundColor(context.getResources().getColor(R.color.itemColor));
        } else {
            binding.ll.setBackgroundColor(context.getResources().getColor(R.color.white));
        }

        binding.tvXm.setText(bean.getXm());

        if (bean.getIszzpfzr()!=null&&bean.getIszzpfzr().equals("1")){
            binding.tvXm.setText(bean.getXm()+"(工作负责人)");
        }

        binding.tvSfzh.setText(bean.getSfzh());
        binding.tvPszb.setText(bean.getPszbName());
        binding.tvYyrq.setText(bean.getYyrq());

        binding.tvPsbm.setText(bean.getPsbmName());
        binding.tvPsbz.setText(bean.getPsbzName());
        binding.imageViewDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(deleteItemListener!=null){
                    deleteItemListener.deleteItem(bean.getSfzh());
                }
            }
        });

    }

    @Override
    protected AdapterAppointmentMemberBinding getBinding(LayoutInflater inflater, ViewGroup parent) {
        return AdapterAppointmentMemberBinding.inflate(inflater, parent, false);
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public interface DeleteItemListener {
        void deleteItem(String sfzh);
    }
}