package com.tenlionsoft.baselib.core.widget.views;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;

import com.tenlionsoft.baselib.R;
import com.tenlionsoft.baselib.core.beans.ConditionBean;
import com.tenlionsoft.baselib.core.beans.OperateBean;
import com.tenlionsoft.baselib.core.widget.OperateAdapter;
import com.tenlionsoft.baselib.core.widget.base.BaseRecyclerAdapter;
import com.tenlionsoft.baselib.core.widget.base.ConditionAdapter;

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

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import razerdp.basepopup.BasePopupWindow;

/**
 * 作者: adam
 * 日期: 2021/9/30 - 2:58 下午
 * 邮箱: itgaojian@163.com
 * 描述: 操作选项
 */
public class OperatePopup extends BasePopupWindow {
    private OperateAdapter mAdapter;
    private List<OperateBean> mDatas;

    public OperatePopup(Context context, List<OperateBean> datas) {
        super(context);
        View view = createPopupById(R.layout.popup_operate_layout);
        RecyclerView rlvActions = view.findViewById(R.id.rlv_actions);
        if (datas == null) {
            mDatas = new ArrayList<>();
        } else {
            mDatas = datas;
        }
        mAdapter = new OperateAdapter(context, mDatas);
        rlvActions.setLayoutManager(new LinearLayoutManager(context));
        rlvActions.setAdapter(mAdapter);
        setContentView(view);

        setBackgroundColor(Color.parseColor("#11000000"));
        setPopupGravity(Gravity.BOTTOM | Gravity.CENTER);
        mAdapter.addOnItemClickListener(operateBean -> mChangeListener.onChecked(operateBean));
    }

    private OnCheckChangeListener mChangeListener;

    public void addOnCheckChange(OnCheckChangeListener listener) {
        this.mChangeListener = listener;
    }

    public interface OnCheckChangeListener {
        void onChecked(OperateBean bean);
    }
}
