package com.danding.yang800;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.danding.yang800.Presenter.MyProfitActivityPresenter;
import com.danding.yang800.Util.ToastUtil;
import com.danding.yang800.View.NetworkProgressDialog;

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

public class MyProfitActivity extends BaseActivity {
    @BindView(R.id.myprofit_allmoneyTv)
    TextView myprofit_allmoneyTv;
    //    @BindView(R.id.myprofit_allprofitTv)
//    TextView myprofitAllprofitTv;
//    @BindView(R.id.myprofit_rewardTv)
//    TextView myprofitRewardTv;
    @BindView(R.id.profit_takebutton)
    TextView profitTakebutton;
    @BindView(R.id.myProfit_backTv)
    TextView myProfit_backTv;
    @BindView(R.id.myprofit_detailedLayout)
    RelativeLayout myprofit_detailedLayout;
    @BindView(R.id.myprofit_takeNotes_Layout)
    RelativeLayout myprofit_takeNotes_Layout;
    @BindView(R.id.myProfit_waitApplyLayout)
    RelativeLayout myProfit_waitApplyLayout;
    @BindView(R.id.myprofit_ticket_Layout)
    RelativeLayout myprofit_ticket_Layout;
    @BindView(R.id.myprofit_waitProfitTv)
    TextView myprofit_waitProfitTv;
    @BindView(R.id.myprofit_realNameTv)
    TextView myprofit_realNameTv;
    private NetworkProgressDialog pd;
    MyProfitActivityPresenter presenter;
    String storeId = "";
    SharedPreferences sp;
    String money = "";
    boolean setrealName;
    String name = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        setContentView(R.layout.activity_my_profit);
        ButterKnife.bind(this);
        sp = getSharedPreferences("variable", Context.MODE_PRIVATE);
        storeId = sp.getString("storeId", "");
        presenter = new MyProfitActivityPresenter(this);

        initDialog();

    }
    @OnClick({R.id.profit_takebutton, R.id.myProfit_backTv, R.id.myprofit_detailedLayout, R.id.myprofit_takeNotes_Layout
            , R.id.myProfit_waitApplyLayout, R.id.myprofit_ticket_Layout})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.profit_takebutton:
                if (setrealName) {
                    startActivity(InputAliAccountActivity.class);
                    myprofit_realNameTv.setVisibility(View.GONE);
//                startActivity(TakeOutActivity.class);
                    sp.edit().putString("money", money).commit();
                } else {
                    myprofit_realNameTv.setVisibility(View.VISIBLE);
                    ToastUtil.show(MyProfitActivity.this, "请先实名认证");
                }
                break;
            case R.id.myprofit_detailedLayout:
                startActivity(AccountDetailedActivity.class);
                break;
            case R.id.myprofit_takeNotes_Layout:
                startActivity(TakeNotesActivity.class);
                break;
            case R.id.myProfit_backTv:
                finish();
                break;
            case R.id.myProfit_waitApplyLayout:
                startActivity(WaitProfitActivity.class);
                break;
            case R.id.myprofit_ticket_Layout:
                startActivity(MyTicketActivity.class);
                break;
        }

    }

    public void initDialog() {
        if (pd == null) {
            pd = NetworkProgressDialog.createDialog(this);
            if (!pd.isShowing()) {
                pd.show();
            }
        }
    }

    public void dismissDialog() {
        if (pd != null) {
            pd.dismiss();
            pd = null;
            NetworkProgressDialog.clear();
        }
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        initDialog();
        presenter.balance(storeId);
//        presenter.cashWithdrawApplySum(storeId);
    }

    public void updateBalance(String balance) {
        myprofit_allmoneyTv.setText(balance);
        money = balance;
    }

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

    @Override
    protected void onDestroy() {
        super.onDestroy();
        sp.edit().putString("money", "").commit();
    }

    public void initData(boolean realNameSet, String realname) {
        setrealName = realNameSet;
        name = realname;
    }

    public void updateWaitProfit(String profit) {
        myprofit_waitProfitTv.setText(profit);
    }
}
