package com.rehome.meetingbook.adapter;

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

import com.bumptech.glide.Glide;
import com.rehome.meetingbook.Contans;
import com.rehome.meetingbook.R;
import com.rehome.meetingbook.bean.ContactListBean;
import com.rehome.meetingbook.databinding.AdapterAppointmentResultBinding;
import com.rehome.meetingbook.databinding.AdapterContactBinding;

import java.util.List;

/**
 * Create By HuangWenFei
 * 创建日期：2022-12-08 14:29
 * 描述：
 */
public class ContactAdapter extends MyAdapter<AdapterContactBinding>{
    private final Context context;
    private final List<ContactListBean.RowsBean.OrderlistBean> datas;

    public ContactAdapter(Context context, List<ContactListBean.RowsBean.OrderlistBean> datas) {
        super(context);
        this.datas = datas;
        this.context=context;
    }

    @Override
    protected void handleData(int position, AdapterContactBinding binding) {
        ContactListBean.RowsBean.OrderlistBean item = datas.get(position);

        if (!TextUtils.isEmpty(item.getName())) {
            binding.ll.setVisibility(View.VISIBLE);
            binding.tvDeptName.setVisibility(View.GONE);
            binding.tvName.setText(item.getName());
            binding.tvPhone1.setText(item.getTelephone());
            binding.tvPhone2.setText(item.getAddress_tel());

            if (!item.getAccount_head().equals("")) {
                Glide.with(context).load(Contans.BASE_URL + item.getAccount_head()).into(binding.headView);
            } else {
                binding.headView.setImageResource(R.drawable.head_photo);
            }

        } else {

            if (position == 0) {
                binding.tvDeptName.setVisibility(View.GONE);
                binding.ll.setVisibility(View.GONE);
            } else {
                binding.tvDeptName.setText(item.getGroupName());
                binding.ll.setVisibility(View.GONE);
                binding.tvDeptName.setVisibility(View.VISIBLE);
            }
        }
    }

    @Override
    protected AdapterContactBinding getBinding(LayoutInflater inflater, ViewGroup parent) {
        return AdapterContactBinding.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;
    }
}