package com.ez.ertc.meeting.ui;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;

import com.ez.ertc.meeting.R;
import com.ez.ertc.meeting.R2;
import com.ez.ertc.meeting.base.YsBaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public
/**
 *
 *
 * @author xiezuoyuan
 * @time 2021/11/4 19:53
 */
class TestConfigActivity extends YsBaseActivity {
    public static void start(Context context) {
        Intent starter = new Intent(context, TestConfigActivity.class);
        context.startActivity(starter);
    }
    @BindView(R2.id.tvCost10S)
    TextView tvCost10S;
    @BindView(R2.id.tvCost30S)
    TextView tvCost30S;
    @BindView(R2.id.swUpMbps)
    Switch swUpMbps;
    @BindView(R2.id.swDownMbps)
    Switch swDownMbps;
    @BindView(R2.id.llUpMbps)
    LinearLayout llUpMbps;
    @BindView(R2.id.llDownMbps)
    LinearLayout llDownMbps;
    @BindView(R2.id.tvUp1Mbps)
    TextView tvUp1Mbps;
    @BindView(R2.id.tvUp2Mbps)
    TextView tvUp2Mbps;
    @BindView(R2.id.tvUp4Mbps)
    TextView tvUp4Mbps;
    @BindView(R2.id.tvUp6Mbps)
    TextView tvUp6Mbps;
    @BindView(R2.id.tvUp8Mbps)
    TextView tvUp8Mbps;
    @BindView(R2.id.tvUp12Mbps)
    TextView tvUp12Mbps;
    @BindView(R2.id.tvDown1Mbps)
    TextView tvDown1Mbps;
    @BindView(R2.id.tvDown2Mbps)
    TextView tvDown2Mbps;
    @BindView(R2.id.tvDown4Mbps)
    TextView tvDown4Mbps;
    @BindView(R2.id.tvDown6Mbps)
    TextView tvDown6Mbps;
    @BindView(R2.id.tvDown8Mbps)
    TextView tvDown8Mbps;
    @BindView(R2.id.tvDown12Mbps)
    TextView tvDown12Mbps;
    private int upSpeed,downSpeed,duration;
    @Override
    protected int provideLayoutId() {
        return R.layout.ys_mt_activity_test_config;
    }

    @SuppressLint("NewApi")
    @Override
    protected void initView() {
        ButterKnife.bind(this);
        swUpMbps.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                llUpMbps.setVisibility(isChecked ? View.VISIBLE : View.GONE);
            }
        });
        swDownMbps.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                llDownMbps.setVisibility(isChecked ? View.VISIBLE : View.GONE);
            }
        });
    }

    @Override
    protected void initData() {
        tvCost10S.setTag(10);
        tvCost30S.setTag(30);
        tvUp1Mbps.setTag(1024);
        tvUp2Mbps.setTag(2048);
        tvUp4Mbps.setTag(4096);
        tvUp6Mbps.setTag(6144);
        tvUp8Mbps.setTag(8192);
        tvUp12Mbps.setTag(12288);
        tvDown1Mbps.setTag(1024);
        tvDown2Mbps.setTag(2048);
        tvDown4Mbps.setTag(4096);
        tvDown6Mbps.setTag(6144);
        tvDown8Mbps.setTag(8192);
        tvDown12Mbps.setTag(12288);
        onSelectCost(tvCost10S);
        onSelectUpMbps(tvUp1Mbps);
        onSelectDownMbps(tvDown1Mbps);
    }

    @OnClick({R2.id.tvUp1Mbps,R2.id.tvUp2Mbps,R2.id.tvUp4Mbps,
            R2.id.tvUp6Mbps,R2.id.tvUp8Mbps,R2.id.tvUp12Mbps,
            R2.id.tvDown1Mbps,R2.id.tvDown2Mbps,R2.id.tvDown4Mbps,
            R2.id.tvDown6Mbps,R2.id.tvDown8Mbps,R2.id.tvDown12Mbps,
            R2.id.tvCost30S,R2.id.tvCost10S,R2.id.btnOk})
    public void onClick(View view){
        int id = view.getId();
        if (id == R.id.tvUp1Mbps){
            onSelectUpMbps(view);
        } else if (id == R.id.tvUp2Mbps){
            onSelectUpMbps(view);
        } else if (id == R.id.tvUp4Mbps){
            onSelectUpMbps(view);
        } else if (id == R.id.tvUp6Mbps){
            onSelectUpMbps(view);
        } else if (id == R.id.tvUp8Mbps){
            onSelectUpMbps(view);
        } else if (id == R.id.tvUp12Mbps){
            onSelectUpMbps(view);
        } else if (id == R.id.tvDown1Mbps){
            onSelectDownMbps(view);
        } else if (id == R.id.tvDown2Mbps){
            onSelectDownMbps(view);
        } else if (id == R.id.tvDown4Mbps){
            onSelectDownMbps(view);
        } else if (id == R.id.tvDown6Mbps){
            onSelectDownMbps(view);
        } else if (id == R.id.tvDown8Mbps){
            onSelectDownMbps(view);
        } else if (id == R.id.tvDown12Mbps){
            onSelectDownMbps(view);
        } else if (id == R.id.tvCost30S){
            onSelectCost(view);
        } else if (id == R.id.tvCost10S){
            onSelectCost(view);
        } else if (id == R.id.btnOk){
            try {
                ErtcTestingActivity.start(this, swUpMbps.isChecked() ? upSpeed : 0, swDownMbps.isChecked() ? downSpeed : 0, duration);
            } catch (Exception e){
                e.printStackTrace();
            }
        }
    }

    private void onSelectUpMbps(View view){
        upSpeed = (int) view.getTag();
        tvUp1Mbps.setSelected(false);
        tvUp2Mbps.setSelected(false);
        tvUp4Mbps.setSelected(false);
        tvUp6Mbps.setSelected(false);
        tvUp8Mbps.setSelected(false);
        tvUp12Mbps.setSelected(false);
        view.setSelected(true);
    }
    private void onSelectDownMbps(View view){
        downSpeed = (int) view.getTag();
        tvDown1Mbps.setSelected(false);
        tvDown2Mbps.setSelected(false);
        tvDown4Mbps.setSelected(false);
        tvDown6Mbps.setSelected(false);
        tvDown8Mbps.setSelected(false);
        tvDown12Mbps.setSelected(false);
        view.setSelected(true);
    }
    private void onSelectCost(View view){
        duration = (int) view.getTag();
        tvCost30S.setSelected(false);
        tvCost10S.setSelected(false);
        view.setSelected(true);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
