package com.genlot.ninglottery.game.d3.betview;

import android.content.Context;
import android.widget.TextView;

import com.genlot.ninglottery.R;
import com.genlot.ninglottery.event.BetChangeEvent;
import com.genlot.ninglottery.game.bet.BetView;
import com.genlot.ninglottery.game.bet.IBetBean;
import com.genlot.ninglottery.widget.BetTextView;

import org.greenrobot.eventbus.EventBus;

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

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author ZhuYongKang
 * @description 3D组选复式界面
 * @date 2019/10/16
 */
public class MultiBoxView extends BetView {

    private Class mType;

    public MultiBoxView(Context context, Class type) {
        super(context);
        this.mType = type;
        initData();
    }

    @OnClick(R.id.rv_clear1)
    public void clearOneBet(TextView view) {
        IBetBean bean = mBetList.get(0);
        bean.clear();
        mTextBet.setText(bean.getAllNumberList());
        EventBus.getDefault().post(new BetChangeEvent(bean));
    }

    @Override
    public void rowChange(int newRow) {
    }

    public void refreshRow() {
        mTextBet.setText(mBetList.get(0).getAllNumberList());
    }

    @Override
    public int getLayoutID() {
        return R.layout.view_multi_d3_row1;
    }

    @Override
    protected void initData() {
        try {
            IBetBean bean = (IBetBean) mType.newInstance();
            mBetList.add(bean);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void clear() {
        mBetList.get(0).clear();
        refreshRow();
    }

    @Override
    public String[] getBetData() {
        List<String> betList = new ArrayList<>();
        for (IBetBean bean : mBetList) {
            if (bean.isFull()) {
                betList.add(bean.toBetString());
            }
        }
        return betList.toArray(new String[0]);
    }

    @Override
    public void parseBetData(String[] betData) {
        mBetList.get(0).parseBetData(betData[0]);
        mTextBet.setText(mBetList.get(0).getAllNumberList());
    }

    public void changeBetSize(int count, int spaceH, int spaceV) {
        mTextBet.changeBetSize(count, spaceH, spaceV);
    }

    @BindView(R.id.tv_bet_info1)
    BetTextView mTextBet;
}
