package com.tenlionsoft.oamodule.adapter;

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


import com.tenlionsoft.baselib.core.widget.base.BaseRecyclerAdapter;
import com.tenlionsoft.oamodule.R;
import com.tenlionsoft.oamodule.beans.DepartmentListBean;
import com.tenlionsoft.oamodule.holder.SelDeptHolder;

import java.util.List;

/**
 * 作者: adam
 * 日期: 2020/11/17 - 1:22 PM
 * 邮箱: itgaojian@163.com
 * 描述: 选中的部门
 */
public class SelDeptAdapter extends BaseRecyclerAdapter<DepartmentListBean, SelDeptHolder> {
    public SelDeptAdapter(Context ctx, List<DepartmentListBean> list) {
        super(ctx, list);
    }

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

    @Override
    public void bindHolder(SelDeptHolder holder, int i) {
        DepartmentListBean bean = mData.get(i);
        holder.mTvName.setText(bean.getDepartmentName());
        if (i == (mData.size() - 1)) {
            holder.mIvArrow.setVisibility(View.GONE);
            holder.mTvName.setTextColor(Color.parseColor("#00A6FE"));
        } else {
            holder.mIvArrow.setVisibility(View.VISIBLE);
            holder.mTvName.setTextColor(Color.BLACK);
        }
        if (mOnItemChoose != null) {
            holder.itemView.setOnClickListener(v -> mOnItemChoose.onItemChoose(bean, i));
        }
    }

    private OnItemChoose mOnItemChoose;

    public void setOnItemChoose(OnItemChoose onItemChoose) {
        this.mOnItemChoose = onItemChoose;
    }

    public interface OnItemChoose {
        void onItemChoose(DepartmentListBean bean, int pos);
    }
}
