package com.taikor.investment.modules.group;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

import com.taikor.investment.R;
import com.taikor.investment.base.BaseActivity;
import com.taikor.investment.mylibrary.TAnalytics;
import com.taikor.investment.utils.ToastUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 自定义
 * Created by Any on 2017/4/13.
 */
public class DefineActivity extends BaseActivity {
    
    @BindView(R.id.tv_bar_title)
    TextView tvTitle;
    @BindView(R.id.tv_bar_right)
    TextView tvRight;
    @BindView(R.id.et_group_name)
    EditText etGroupName;//组合名称
    @BindView(R.id.et_group_desc)
    EditText etGroupDesc;//组合描述
    @BindView(R.id.et_define_invest_money)
    EditText etInvestMoney;//投资金额
    @BindView(R.id.cb_share)
    CheckBox cbShare;//是否分享

    @Override
    public int getContentViewId() {
        return R.layout.activity_group_define;
    }

    @Override
    public void initView() {
        tvTitle.setText("自定义组合");
        tvRight.setText(getString(R.string.next_step));
        tvRight.setVisibility(View.VISIBLE);
    }

    @OnClick({R.id.tv_bar_back, R.id.tv_bar_right})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_bar_back:
                finish();
                break;
            case R.id.tv_bar_right://跳转到添加产品页面
                transmitData();
                break;
        }
    }

    /**
     * 传递数据
     */
    private void transmitData() {
        String portfolioName = etGroupName.getText().toString();
        String investmentAmount = etInvestMoney.getText().toString();
        if (TextUtils.isEmpty(portfolioName) || TextUtils.isEmpty(investmentAmount)) {
            ToastUtils.showShort(DefineActivity.this, "组合名称和投资金额不能为空");
            return;
        }
        Intent intent = new Intent(DefineActivity.this, SetRepoActivity.class);
        intent.putExtra("portfolio_name", portfolioName);
        intent.putExtra("description", etGroupDesc.getText().toString());
        intent.putExtra("investment_amount", investmentAmount);
        intent.putExtra("share", cbShare.isChecked());
        startActivity(intent);
        finish();
    }

    //埋点
    @Override
    protected void onResume() {
        super.onResume();
//        TAnalytics.onPageStart("selfDefinePage");
    }

    @Override
    protected void onPause() {
        super.onPause();
//        TAnalytics.onPageLoad("selfDefinePage","groupPage","","");
    }
}
