package com.dskj.daikuan.ui.activity;
import android.content.Intent;
import android.os.Build;
import android.view.View;
import android.widget.EditText;

import androidx.annotation.RequiresApi;
import androidx.lifecycle.ViewModelProviders;

import com.azhon.basic.base.BaseActivity;
import com.bumptech.glide.Glide;
import com.dskj.daikuan.R;
import com.dskj.daikuan.api.Api;
import com.dskj.daikuan.api.BaseObserver;
import com.dskj.daikuan.api.Result;
import com.dskj.daikuan.bean.ListBean;
import com.dskj.daikuan.bean.LoanBean;
import com.dskj.daikuan.databinding.ActivityShenqingBinding;
import com.dskj.daikuan.databinding.ActivityXiangqingBinding;
import com.dskj.daikuan.viewModel.home.MainViewModel;

import java.util.ArrayList;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;


public class XiangQingActivity extends BaseActivity<MainViewModel, ActivityXiangqingBinding> {
    int id = 0;
    public LoanBean loanBean;
    @Override
    protected MainViewModel initViewModel() {
        return ViewModelProviders.of(this).get(MainViewModel.class);
    }

    @Override
    protected void showError(Object obj) {

    }

    @Override
    protected int initLayout() {
        return R.layout.activity_xiangqing;
    }

    @RequiresApi(api = Build.VERSION_CODES.Q)
    @Override
    protected void initView() {
       dataBinding.topLyF.backButton.setOnClickListener(view -> finish());
       dataBinding.topLyF.titleTv.setText("Loan Info");
       id = getIntent().getIntExtra("id",0);
       dataBinding.topLyF.menuTv.setVisibility(View.VISIBLE);
       dataBinding.topLyF.menuTv.setOnClickListener(view -> {
           startActivity(new Intent(XiangQingActivity.this,MainActivity.class));
       });

    }
    @Override
    protected void initData() {
        Api.getInstance().detail(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<>() {

                    @Override
                    public void onSuccess(Result<LoanBean> feedbackResp) {
                        loanBean = feedbackResp.data;
                        changeInfo();
                    }

                    @Override
                    public void onError(int code, String msg) {

                    }
                });
    }

    private void changeInfo() {
        dataBinding.fullnameEt.setText(loanBean.getFull_name());
        dataBinding.icEt.setText(loanBean.getIc_code());
        dataBinding.phoneNumberEt.setText(loanBean.getPhone());
        dataBinding.occupationEt.setText(loanBean.getOccupation());
        dataBinding.addressEt.setText(loanBean.getAddress());
        dataBinding.beneficiaryBankEt.setText(loanBean.getBank_name());
        dataBinding.beneficiaryAccountNoEt.setText(loanBean.getBank_code());
        dataBinding.salaryEt.setText(loanBean.getSalary());
        dataBinding.loanAmountEt.setText(loanBean.getAmount());
        dataBinding.salaryEt.setText(loanBean.getSalary());

        Glide.with(XiangQingActivity.this).load(loanBean.getId_front()).placeholder(R.mipmap.sfzzm).error(R.mipmap.sfzzm).into(dataBinding.zhengmianIv);
        Glide.with(XiangQingActivity.this).load(loanBean.getId_back()).placeholder(R.mipmap.sfzbm).error(R.mipmap.sfzbm).into(dataBinding.fanmianIv);



        dataBinding.statusTv.setTextColor(getResources().getColor(R.color.white));
        if(loanBean.getStatus() == 0){
            dataBinding.statusTv.setText("processing");

        }else if(loanBean.getStatus() == 1){
            dataBinding.statusTv.setText("success");

        }else if(loanBean.getStatus() == 2){
            dataBinding.statusTv.setText("fail");
            dataBinding.statusTv.setTextColor(getResources().getColor(R.color.color_search_2));

        }

    }

}