package com.gingersoft.gsa.cloud.table.mvp.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;

import com.gingersoft.gsa.cloud.database.bean.Function;
import com.gingersoft.gsa.cloud.table.R;
import com.gingersoft.gsa.cloud.table.R2;
import com.jess.arms.base.BaseHolder;
import com.jess.arms.base.DefaultAdapter;
import com.qmuiteam.qmui.alpha.QMUIAlphaButton;

import java.util.List;

import butterknife.BindView;

/**
 * 作者：ELEGANT_BIN
 * 版本：1.6.0
 * 创建日期：2018/6/27
 * 修订历史：2018/6/27
 * 描述：
 */

public class OrderTopFunctionAdapter extends DefaultAdapter<Function> {

    private Context mContext;

    public OrderTopFunctionAdapter(Context context, List<Function> infos) {
        super(infos);
        this.mContext = context;

    }

    @Override
    public int getItemCount() {
        return mInfos.size();
    }

    @Override
    public BaseHolder<Function> getHolder(View v, int viewType) {
        return new TopFunctionItemHolder(v);
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.meal_order_top_function;
    }

    class TopFunctionItemHolder extends BaseHolder<Function> {

        @BindView(R2.id.btn_name)
        Button btn_name;
        @BindView(R2.id.btn_lable)
        Button btn_lable;

        public TopFunctionItemHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void setData(Function datasBean, int position) {

            btn_name.setText(datasBean.getResName());
            btn_name.setTextColor(datasBean.getTextColor());
            btn_name.setBackgroundColor(datasBean.getBackgroundColor());
            btn_name.setTextSize(datasBean.getTextSize());

            if (!TextUtils.isEmpty(datasBean.getLable())) {
                btn_lable.setText(datasBean.getLable());
                btn_lable.setVisibility(View.VISIBLE);
            } else {
                btn_lable.setVisibility(View.INVISIBLE);
            }

            btn_name.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onClickListener != null)
                        onClickListener.onItemClick(v, datasBean);
                }
            });
            btn_name.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    if (onClickListener != null)
                        onClickListener.onItemLongClick(v, datasBean);
                    return false;
                }
            });
        }
    }

    private OnClickListener onClickListener;

    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public interface OnClickListener {

        void onItemClick(View v, Function function);

        boolean onItemLongClick(View v, Function function);

    }
}
