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

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.database.bean.Discount;
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.jess.arms.utils.ArmsUtils;
import com.jess.arms.utils.DeviceUtils;

import java.util.List;

import butterknife.BindView;

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

public class DiscountAdapter extends DefaultAdapter<Discount> {

    private Context mContext;


    private int fontSize;
    private int colWidth;
    private int colHeight;

    private int currentSelectPosition = 0;

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

        fontSize = GsaCloudApplication.androidSetting.getModFontSize();
//        int DetailColCount = GSAApplication.androidSetting.getDiscountCol();
//        colWidth = (int) (DeviceUtils.getScreenWidth(mContext) / DetailColCount);
//        colHeight = GSAApplication.androidSetting.getModBtnHeight();
    }

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

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

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

    class DiscountItemHolder extends BaseHolder<Discount> {

        @BindView(R2.id.tv_name)
        TextView tv_name;

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

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

            initName(datasBean);
            setColor(datasBean);
        }

        private void initName(Discount datasBean) {
            String desc = datasBean.getRemark();
            tv_name.setText(desc);
            tv_name.setTextSize(fontSize);

//            tv_name.setMaxWidth(colWidth);
//            tv_name.setWidth(colWidth);
//            tv_name.setHeight(colHeight);
        }

        private void setColor(Discount datasBean) {

            int color = ArmsUtils.getColor(mContext, R.color.light_blue_900);
            int fontColor = ArmsUtils.getColor(mContext, R.color.theme_white_color);

            tv_name.setBackgroundColor(color);
            tv_name.setTextColor(fontColor);
        }
    }

    private OnItemClickListener mOnItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {

        void onItemClick(Discount datasBean, int position);

    }
}
