package app.brest.app.brest.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.ArrayList;

import app.brest.testmin3d.R;

/**
 * Created by ptitcois on 31/10/16.
 */
public class SelectButton extends LinearLayout implements View.OnClickListener {
    protected String[] mData;
    protected Button mLeft;
    protected Button mRight;
    protected TextView mText;
    protected int mState = 0;
    protected int mHeight=60;
    protected void setLParams(View v, int w, int h)
    {
        LayoutParams l =new LayoutParams(w,h);
        l.setMargins(0,0,0,0);
        v.setLayoutParams(l);
    }

    public SelectButton(Context context, String[] m) {
        super(context);
        setOrientation(HORIZONTAL);
        mData=m;
        mLeft = new Button(context);
        mLeft.setBackgroundResource(R.drawable.arrow_left);
        mLeft.setOnClickListener(this);

        mRight = new Button(context);
        mRight.setBackgroundResource(R.drawable.arrow_right);
        mRight.setOnClickListener(this);

        mText = new TextView(context);
        if(mData.length>0)
            mText.setText(mData[mState]);


        addView(mLeft);
        addView(mText);
        addView(mRight);
        setLParams(mLeft, mHeight, mHeight);
        setLParams(mRight, mHeight, mHeight);
        setLParams(mText, 200 , mHeight);
        mText.setTextColor(getResources().getColor(R.color.dull_4));

    }

    public void setState(int i)
    {
        if(mData.length>i)
            mText.setText(mData[mState=i]);
    }

    public int getState()
    {
        return mState;
    }

    @Override
    public void onClick(View view) {
        if(view==mLeft)
        {
            mState=(mState-1<0) ? (mData.length-1) : (mState-1);
        }else if(view==mRight)
        {
            mState=(mState==mData.length-1) ? 0 : (mState+1);
        }
        mText.setText(mData[mState]);
    }
}
