package com.tenlionsoft.oamodule.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.tenlionsoft.baselib.core.widget.base.BaseRecyclerAdapter;
import com.tenlionsoft.oamodule.R;
import com.tenlionsoft.oamodule.beans.PersonShowBean;
import com.tenlionsoft.oamodule.holder.BasePersonShowHolder;

import java.util.List;

/**
 * 作者: adam
 * 日期: 2022/4/14 - 15:48
 * 邮箱: itgaojian@163.com
 * 描述:
 */
public class BasePersonShowAdapter extends BaseRecyclerAdapter<PersonShowBean, BasePersonShowHolder> {
    private int mType = 1;

    public BasePersonShowAdapter(Context ctx, List<PersonShowBean> list, int type) {
        super(ctx, list);
        this.mType = type;
    }

    @Override
    public BasePersonShowHolder createHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(mContext).inflate(R.layout.item_person_base_show, parent, false);
        return new BasePersonShowHolder(itemView);
    }

    @Override
    public void bindHolder(BasePersonShowHolder h, int i) {
        PersonShowBean b = mData.get(i);

        if (!TextUtils.isEmpty(b.getId())) {
            h.mTvName.setVisibility(View.VISIBLE);
            if (mType == 2) {
                //单纯显示
                h.mIvDel.setVisibility(View.GONE);
            } else {
                //可以删除
                h.mIvDel.setVisibility(View.VISIBLE);
            }
            h.mTvName.setText(mData.get(i).getName());
            Glide.with(mContext)
                .load(R.drawable.ic_user_default)
                .into(h.mIvUserIcon);
            if (mDelListener != null) {
                h.mIvDel.setOnClickListener(v -> mDelListener.doDel(mData.get(i), i));
            }
        } else {
            h.mTvName.setVisibility(View.GONE);
            h.mIvDel.setVisibility(View.GONE);
            Glide.with(mContext)
                .load(R.drawable.ic_file_add)
                .into(h.mIvUserIcon);
        }
    }

    private OnDelListener mDelListener;

    public void addOnDelListener(OnDelListener listener) {
        this.mDelListener = listener;
    }

    public interface OnDelListener {
        void doDel(PersonShowBean bean, int i);
    }
}
