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

import android.content.Context;
import android.graphics.Color;
import android.widget.LinearLayout;
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.game.qlc.bean.Base7lc;
import com.genlot.ninglottery.widget.BetTextView;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import butterknife.BindViews;
import butterknife.OnClick;

/**
 * @author ZhuYongKang
 * @description 七乐彩胆拖投注界面
 * @date 2019/8/26
 */
public class Base7lcView extends BetView {

    public Base7lcView(Context context) {
        super(context);
        initData();
    }

    @OnClick({R.id.ll_dan, R.id.ll_tuo})
    public void betClicked(LinearLayout view) {
        int newRow = mLlBets.indexOf(view);
        if (mCurrentRow != newRow) {
            rowChange(newRow);
            EventBus.getDefault().post(new BetChangeEvent(mBetList.get(0)));
        }
    }

    @OnClick({R.id.tv_clear_dan, R.id.tv_clear_tuo})
    public void clearRow(TextView view) {
        int newRow = mTextClears.indexOf(view);
        Base7lc bean = (Base7lc) mBetList.get(0);
        switch (view.getId()) {
            case R.id.tv_clear_dan:
                bean.mDanList.clear();
                break;
            case R.id.tv_clear_tuo:
                bean.mRedList.clear();
                break;
        }
        mTextBets.get(newRow).clearText();
        if (mCurrentRow != newRow) {
            rowChange(newRow);
        }
        EventBus.getDefault().post(new BetChangeEvent(bean));
    }

    @Override
    public void rowChange(int newRow) {
        mCurrentRow = newRow;
        for (int i = 0; i < mLlBets.size(); i++) {
            if (i == newRow) {
                mLlBets.get(i).setBackground(mContext.getDrawable(R.drawable.shape_bet_select));
                mTextSeries.get(i).setBackground(mContext.getDrawable(R.mipmap.bet_series_select));
                mTextSeries.get(i).setTextColor(Color.WHITE);
                mTextClears.get(i).setBackground(mContext.getDrawable(R.mipmap.clear_single_select));
            } else {
                mLlBets.get(i).setBackground(null);
                mTextSeries.get(i).setBackground(mContext.getDrawable(R.mipmap.bet_series_normal));
                mTextSeries.get(i).setTextColor(Color.parseColor("#FF706969"));
                mTextClears.get(i).setBackground(mContext.getDrawable(R.mipmap.clear_single_normal));
            }
        }
    }

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

    public void refreshDan() {
        mTextBets.get(0).setText(((Base7lc) mBetList.get(0)).mDanList);
    }

    public void refreshTuo() {
        mTextBets.get(1).setText(((Base7lc) mBetList.get(0)).mRedList);
    }

    @Override
    protected void initData() {
        IBetBean bean = new Base7lc();
        mBetList.add(bean);
    }

    @Override
    public void clear() {
        rowChange(0);
        mBetList.get(0).clear();
        for (BetTextView view : mTextBets) {
            view.clearText();
        }
    }

    @Override
    public String[] getBetData() {
        String[] betData = new String[1];
        IBetBean bean = mBetList.get(0);
        betData[0] = bean.toBetString();
        return betData;
    }

    @Override
    public void parseBetData(String[] betData) {
        mBetList.get(0).parseBetData(betData[0]);
        refreshDan();
        refreshTuo();
    }

    @BindViews({R.id.ll_dan, R.id.ll_tuo})
    List<LinearLayout> mLlBets;
    @BindViews({R.id.tv_series_dan,R.id.tv_series_tuo})
    List<TextView> mTextSeries;
    @BindViews({R.id.tv_clear_dan, R.id.tv_clear_tuo})
    List<TextView> mTextClears;
    @BindViews({R.id.tv_bet_dan,R.id.tv_bet_tuo})
    List<BetTextView> mTextBets;
}
