package com.danding.yang800;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.danding.yang800.Presenter.TakeOutActivityPresenter;
import com.danding.yang800.Util.StatusColorUtil;
import com.danding.yang800.Util.ToastUtil;
import com.yanzhenjie.sofia.Sofia;

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

public class TakeOutActivity extends BaseActivity {

    @BindView(R.id.take_out_bankLayout)
    RelativeLayout take_out_bankLayout;
    @BindView(R.id.take_out_AliPayLayout)
    RelativeLayout take_out_AliPayLayout;
    @BindView(R.id.takeout_backTv)
    TextView takeout_backTv;
    TakeOutActivityPresenter presenter;
    SharedPreferences sp;
    @BindView(R.id.takeout_realNameTv)
    TextView takeout_realNameTv;
    boolean setrealName;
    String name="";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        int type = StatusColorUtil.StatusBarLightMode(this);
//        if (type > 0) {
//            StatusColorUtil.setStatusBarColor(this, R.color.white);
//            StatusColorUtil.StatusBarLightMode(this, type);
//        }
        setContentView(R.layout.activity_take_out);
        Sofia.with(this).statusBarDarkFont().statusBarBackground(ContextCompat.getColor(this, R.color.white));
        ButterKnife.bind(this);
        sp = getSharedPreferences("variable", Context.MODE_PRIVATE);
        presenter = new TakeOutActivityPresenter(this);

    }

    @Override
    protected void onResume() {
        super.onResume();
        presenter.getInfo(sp.getInt("userId", 0) + "");
    }

    @OnClick({R.id.take_out_bankLayout, R.id.take_out_AliPayLayout, R.id.takeout_backTv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.take_out_bankLayout:
                if (setrealName) {
                    Intent intent=new Intent(TakeOutActivity.this,BankInfoActivity.class);
                    intent.putExtra("name",name);
                    startActivity(intent);
                } else {
                    ToastUtil.show(TakeOutActivity.this, "请先实名认证");
                }

                break;
            case R.id.take_out_AliPayLayout:
                if (setrealName) {
                    startActivity(InputAliAccountActivity.class);
                } else {
                    ToastUtil.show(TakeOutActivity.this, "请先实名认证");
                }
                break;
            case R.id.takeout_backTv:
                finish();
                break;

        }

    }

    public void initData(boolean realNameSet,String realname) {
        setrealName = realNameSet;
        name=realname;
        if (realNameSet) {
            takeout_realNameTv.setVisibility(View.GONE);
        } else {
            takeout_realNameTv.setVisibility(View.VISIBLE);
        }
    }

}
