package com.genlot.ninglottery.game.common;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.genlot.ninglottery.R;
import com.genlot.ninglottery.game.bet.BetNumber;
import com.genlot.ninglottery.game.d3.bean.BaseD3;
import com.genlot.ninglottery.game.qlc.bean.Bet7lc;
import com.genlot.ninglottery.game.ssq.bean.BetSSQ;

import java.util.List;

/**
 * @author ZhuYongKang
 * @description 选号Adapter
 * @date 2019/8/23
 */
public class NumberAdapter extends BaseQuickAdapter<BetNumber, BaseViewHolder> {


    public NumberAdapter(int layoutResId, @Nullable List<BetNumber> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, BetNumber item) {
        helper.setText(R.id.tv_number, item.getNumber());
        switch (item.getType()) {
            case BetNumber.NORMAL:
                if (item.isRed()) {
                    helper.setTextColor(R.id.tv_number, Color.parseColor("#FFA02F2F"));
                } else {
                    helper.setTextColor(R.id.tv_number, Color.parseColor("#145B9C"));
                }
                helper.setBackgroundRes(R.id.ll_number, R.mipmap.number_normal);
                helper.setGone(R.id.tv_type, false);
                break;
            case BetNumber.CHECKED:
                if (item.isRed()) {
                    helper.setBackgroundRes(R.id.ll_number, R.mipmap.number_red_select);
                } else {
                    helper.setBackgroundRes(R.id.ll_number, R.mipmap.number_blue_select);
                }
                helper.setGone(R.id.tv_type, false);
                helper.setTextColor(R.id.tv_number, Color.parseColor("#FFFFFFFF"));
                break;
            case BetNumber.DAN:
                helper.setTextColor(R.id.tv_number, Color.parseColor("#FFFFFFFF"));
                helper.setGone(R.id.tv_type, true);
                if (item.isBase()) {
                    helper.setText(R.id.tv_type, "((胆))");
                }
                helper.setBackgroundRes(R.id.ll_number, R.mipmap.number_red_dan);
                break;
            default:
                break;
        }
    }

    /**
     * 双色球界面更改
     */
    public void changeSSQBet(BetSSQ bean, boolean isRed) {
        for (BetNumber number : getData()) {
            number.setType(BetNumber.NORMAL);
        }
        if (isRed) {
            for (BetNumber number : bean.mDanList) {
                BetNumber bet = getData().get(Integer.parseInt(number.getNumber()) - 1);
                bet.setType(number.getType());
            }
            for (BetNumber number : bean.mRedList) {
                BetNumber bet = getData().get(Integer.parseInt(number.getNumber()) - 1);
                bet.setType(number.getType());
            }
        } else {
            for (BetNumber number : bean.mBlueList) {
                BetNumber bet = getData().get(Integer.parseInt(number.getNumber()) - 1);
                bet.setType(number.getType());
            }
        }
        notifyDataSetChanged();
    }

    /**
     * 7乐彩界面更改
     */
    public void change7lcBet(Bet7lc bean) {
        for (BetNumber number : getData()) {
            number.setType(BetNumber.NORMAL);
        }
        for (BetNumber number : bean.mDanList) {
            BetNumber bet = getData().get(Integer.parseInt(number.getNumber()) - 1);
            bet.setType(number.getType());
        }
        for (BetNumber number : bean.mRedList) {
            BetNumber bet = getData().get(Integer.parseInt(number.getNumber()) - 1);
            bet.setType(number.getType());
        }
        notifyDataSetChanged();
    }

    /**
     * 3D游戏更改界面
     */
    public void changeD3Bet(List<BetNumber> list,int startNum) {
        for (BetNumber betNumber : getData()) {
            betNumber.setType(BetNumber.NORMAL);
        }
        for (BetNumber number : list) {
            int index;
            switch (number.getNumber()) {
                case "*":
                case "-":
                    index = 10;
                    break;
                case "小":
                case "偶":
                    index = 0;
                    break;
                case "大":
                case "奇":
                    index = 1;
                    break;
                default:
                    index = Integer.parseInt(number.getNumber()) - startNum;
                    break;
            }
            BetNumber bet = getData().get(index);
            bet.setType(number.getType());
        }
        notifyDataSetChanged();
    }

    /**
     * 3D游戏更改包胆界面
     */
    public void changeD3StraightBase(List<BetNumber> list) {
        for (BetNumber betNumber : getData()) {
            betNumber.setType(BetNumber.NORMAL);
            betNumber.setBase(false);
        }
        if (list.size() == 1) {
            BetNumber number = list.get(0);
            BetNumber bet = getData().get(Integer.parseInt(number.getNumber()));
            bet.setType(number.getType());
            bet.setBase(false);
        } else if (list.size() == 2) {
            BetNumber number1 = list.get(0);
            BetNumber number2 = list.get(1);
            BetNumber bet = getData().get(Integer.parseInt(number1.getNumber()));
            bet.setType(number1.getType());
            if (number1.getNumber().equals(number2.getNumber())) {
                bet.setBase(true);
            } else {
                bet.setBase(false);
                BetNumber bet2 = getData().get(Integer.parseInt(number2.getNumber()));
                bet2.setType(number2.getType());
                bet2.setBase(false);
            }
        }
        notifyDataSetChanged();
    }

    /**
     * 3D游戏更改胆拖界面
     */
    public void changeD3BaseBet(BaseD3 betBean) {
        for (BetNumber betNumber : getData()) {
            betNumber.setType(BetNumber.NORMAL);
            betNumber.setBase(false);
        }
        for (BetNumber tuoNumber : betBean.mTuoList) {
            BetNumber bet = getData().get(Integer.parseInt(tuoNumber.getNumber()));
            bet.setType(tuoNumber.getType());
        }
        int danSize = betBean.mDanList.size();
        if (danSize == 1) {
            BetNumber number = betBean.mDanList.get(0);
            BetNumber bet = getData().get(Integer.parseInt(number.getNumber()));
            bet.setType(number.getType());
            bet.setBase(false);
        } else if (danSize == 2) {
            BetNumber number1 = betBean.mDanList.get(0);
            BetNumber number2 = betBean.mDanList.get(1);
            BetNumber bet = getData().get(Integer.parseInt(number1.getNumber()));
            bet.setType(number1.getType());
            if (number1.getNumber().equals(number2.getNumber())) {
                bet.setBase(true);
            } else {
                bet.setBase(false);
                BetNumber bet2 = getData().get(Integer.parseInt(number2.getNumber()));
                bet2.setType(number2.getType());
                bet2.setBase(false);
            }
        }
        notifyDataSetChanged();
    }

    /**
     * K3游戏更改界面
     */
    public void changeK3Bet(List<BetNumber> list,int startNum) {
        for (BetNumber betNumber : getData()) {
            betNumber.setType(BetNumber.NORMAL);
        }
        for (BetNumber number : list) {
            int index;
            switch (number.getNumber()) {
                case "*":
                    index = 6;
                    break;
                default:
                    index = Integer.parseInt(number.getNumber()) - startNum;
                    break;
            }
            BetNumber bet = getData().get(index);
            bet.setType(number.getType());
        }
        notifyDataSetChanged();
    }

    /**
     * 清空界面
     */
    public void clear() {
        for (BetNumber number : getData()) {
            number.setType(BetNumber.NORMAL);
            number.setBase(false);
        }
        notifyDataSetChanged();
    }

}
