package com.rv.rvmine.adapter;

import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.rv.rvmine.R;
import com.rv.rvmine.bean.TravelerListBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Desc:出游人列表
 */

public class TravelerListAdapter extends BaseQuickAdapter<TravelerListBean.DataBean, BaseViewHolder> {
//    private TravelerListBean.DataBean hasSelectBean = null;

    private int openType;

    public TravelerListAdapter(int openType) {
        super(R.layout.rv_item_traveler_list);
        this.openType = openType;
    }

    @Override
    protected void convert(final BaseViewHolder helper, final TravelerListBean.DataBean item) {
        helper.setText(R.id.tv_name, item.getName());
        helper.setText(R.id.tv_phone, item.getPhone());
        helper.setText(R.id.tv_id_card, item.getIdCard());
//        if (hasSelectBean == null || hasSelectBean != item) {
//            helper.setChecked(R.id.cb_draveler, false);
//        } else {
//            helper.setChecked(R.id.cb_draveler, true);
//        }
        helper.addOnClickListener(R.id.tv_edit);

        if (openType == 0) {
            helper.itemView.findViewById(R.id.cb_draveler).setVisibility(View.GONE);
        } else {
            if (item.getStatus()) {
                helper.setChecked(R.id.cb_draveler, true);
            } else {
                helper.setChecked(R.id.cb_draveler, false);
            }
            helper.itemView.findViewById(R.id.cb_draveler).setEnabled(false);
//            helper.setOnCheckedChangeListener(R.id.cb_draveler, new CompoundButton.OnCheckedChangeListener() {
//                @Override
//                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//
//                    boolean status = item.getStatus();
//                    status = !status;
//                    ((CheckBox) helper.itemView.findViewById(R.id.cb_draveler)).setChecked(status);
//                    item.setStatus(status);
//                    if (status) {
//                        hasSelectBean = item;
//                    } else {
//                        hasSelectBean = null;
//                    }
////                notifyDataSetChanged();
//                }
//            });
        }
    }

    public int getPosition(TravelerListBean.DataBean item) {
        return mData.indexOf(item);
    }

//    public TravelerListBean.DataBean getHasSelectBean() {
//        return hasSelectBean;
//    }

    /**
     * 获取选中的出游人数据
     *
     * @return
     */
    public List<TravelerListBean.DataBean> getSelectItem() {
        List<TravelerListBean.DataBean> list = new ArrayList<>();
        for (TravelerListBean.DataBean dataBean : mData) {
            if (dataBean.getStatus()) {
                list.add(dataBean);
            }
        }
        return list;
    }

}
