package com.hw.nativeapp.ui.activity;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.View;

import com.alibaba.fastjson.JSONArray;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;
import com.hw.nativeapp.R;
import com.hw.nativeapp.utils.ActivityUtils;

import butterknife.OnClick;


public class InfoEnterActivity extends BaseActivity  {

    public static final Integer COUNTDOWN_TIME = 120000;
    private CountDownTimer timer;
    private TitleBar titleBar;

    private String performId = "";
    private String auditoriumId = "";
    private String date = "";
    private String goodsId = "";
    private String salePeice = "";
    private String performTimeId = "";
    private String seatTypeId = "";

    @Override
    void initView() {
        titleBar = findViewById(R.id.tb_main_bar);
        titleBar.setOnTitleBarListener(new OnTitleBarListener() {

            @Override
            public void onLeftClick(View v) {
                ActivityUtils.activityFinish(InfoEnterActivity.this, true );
            }

            @Override
            public void onTitleClick(View v) {

            }

            @Override
            public void onRightClick(View v) {

            }
        });
        getPageTransmitParams();
        startCountDownTimer();
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_info_enter);
    }

    @OnClick({R.id.idCard_btn})
    public void onClick(View v){
        switch (v.getId()){
            case R.id.idCard_btn:
                Bundle bundle = new Bundle();
                bundle.putString("performId", performId);
                bundle.putString("auditoriumId", auditoriumId);
                bundle.putString("performTimeId", performTimeId);
                bundle.putString("seatTypeId", seatTypeId);
                bundle.putString("goodsId", goodsId);
                bundle.putString("salePeice", salePeice);
                bundle.putString("type", "1");
                ActivityUtils.launchActivity(this,InfoInputActivity.class, bundle);
                break;
        }
    }
    //获取页面传递参数
    private void getPageTransmitParams(){
        Intent transmitIntent = getIntent();
        performId = transmitIntent.getStringExtra("performId");
        auditoriumId = transmitIntent.getStringExtra("auditoriumId");
        goodsId = transmitIntent.getStringExtra("goodsId");
        salePeice = transmitIntent.getStringExtra("salePeice");
        performTimeId = transmitIntent.getStringExtra("performTimeId");
        seatTypeId = transmitIntent.getStringExtra("seatTypeId");
    }
    private void jumpToLogin(){
        stopCountDownTimer();
        ActivityUtils.activityFinish(InfoEnterActivity.this, true);
    }
    private void stopCountDownTimer(){
        if (timer != null){
            timer.cancel();
        }
    }
    private void startCountDownTimer(){
        timer = new CountDownTimer(COUNTDOWN_TIME, 1000) {
            @SuppressLint("SetTextI18n")
            @Override
            public void onTick(long millisUntilFinished) {
                titleBar.setRightTitle(millisUntilFinished / 1000 + "s");
            }

            @Override
            public void onFinish() {
                jumpToLogin();
            }
        };
        timer.start();
    }
}