package com.danding.yang800;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.danding.yang800.Adapter.AfterServiceAdapter;
import com.danding.yang800.Entity.AfterServiceInfo;
import com.danding.yang800.General.Yang800App;
import com.danding.yang800.Presenter.AfterServiceActivityPresenter;
import com.danding.yang800.Util.StatusColorUtil;
import com.danding.yang800.Util.ToastUtil;
import com.yanzhenjie.sofia.Sofia;

import java.util.ArrayList;

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

public class AfterServiceActivity extends BaseActivity {
    @BindView(R.id.orderdetails_list)
    ListView orderdetails_list;
    @BindView(R.id.orderdetails_scrollview)
    ScrollView orderdetails_scrollview;
    @BindView(R.id.afterservice_writeLogisticsTv)
    TextView afterservice_writeLogisticsTv;
    @BindView(R.id.afterService_backTv)
    TextView afterService_backTv;
    @BindView(R.id.afterService_statusDescTv)
    TextView afterService_statusDescTv;
    @BindView(R.id.refund_snTv)
    TextView refund_snTv;
    @BindView(R.id.refund_typeDescTv)
    TextView refund_typeDescTv;
    @BindView(R.id.refund_applyRemarkTv)
    TextView refund_applyRemarkTv;
    @BindView(R.id.refund_totalAmountTv)
    TextView refund_totalAmountTv;
    @BindView(R.id.refund_addressNameTv)
    TextView refund_addressNameTv;
    @BindView(R.id.refund_addressNumberTv)
    TextView refund_addressNumberTv;
    @BindView(R.id.refund_addressTv)
    TextView refund_addressTv;
    @BindView(R.id.afterservice_cancelTv)
    TextView afterservice_cancelTv;
    @BindView(R.id.refund_addressLayout)
    LinearLayout refund_addressLayout;
    @BindView(R.id.refund_bottomLayout)
    LinearLayout refund_bottomLayout;
    @BindView(R.id.afterService_moneyLaoyout)
    RelativeLayout afterService_moneyLaoyout;
    AfterServiceAdapter adapter;
    String packageSn;
    AfterServiceActivityPresenter presenter;
    String cancelId;
    String addressName;
    String addressPhone;
    String addressDesc;

    @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_after_service);
        Sofia.with(this).statusBarDarkFont().statusBarBackground(ContextCompat.getColor(this, R.color.white));
        ButterKnife.bind(this);
        Intent intent = getIntent();
        packageSn = intent.getStringExtra("packageSn");
        adapter = new AfterServiceAdapter(this);
        presenter = new AfterServiceActivityPresenter(this, adapter);
        presenter.getInfo(packageSn);
        orderdetails_scrollview.smoothScrollTo(0, 20);


    }

    @OnClick({R.id.afterservice_writeLogisticsTv, R.id.afterService_backTv, R.id.afterservice_cancelTv
    })
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.afterService_backTv:
                finish();
                break;
            case R.id.afterservice_writeLogisticsTv:
                Intent intent = new Intent(AfterServiceActivity.this, WriteLogisticsActivity.class);
                intent.putExtra("addressName", addressName);
                intent.putExtra("addressPhone", addressPhone);
                intent.putExtra("addressDesc", addressDesc);
                intent.putExtra("cancelId", cancelId);
                startActivityForResult(intent, 0);
                break;
            case R.id.afterservice_cancelTv:
                presenter.cacel(cancelId);
                break;
        }
    }

    public void initData(String sn, String statusDesc, String typeDesc, String statusValue, String totalAmount,
                         String receiver, String receiverAddress, String receiverPhone, String applyRemark, String id) {
        addressName = receiver;
        addressPhone = receiverPhone;
        addressDesc = receiverAddress;
        cancelId = id;
        orderdetails_list.setAdapter(adapter);
        refund_snTv.setText(sn);
        afterService_statusDescTv.setText(statusDesc);
        refund_typeDescTv.setText(typeDesc);
        refund_applyRemarkTv.setText(applyRemark);
        refund_totalAmountTv.setText(totalAmount);

        if (statusValue.equals("20")) {
            refund_addressLayout.setVisibility(View.VISIBLE);
        }else {
            refund_addressLayout.setVisibility(View.GONE);
        }
        if (statusValue.equals("5")) {
            afterService_moneyLaoyout.setVisibility(View.VISIBLE);
        }else {
            afterService_moneyLaoyout.setVisibility(View.GONE);
        }
        if (statusValue.equals("20") || statusValue.equals("1")) {
            refund_bottomLayout.setVisibility(View.VISIBLE);
            if (statusValue.equals("20")) {
                afterservice_writeLogisticsTv.setVisibility(View.VISIBLE);
                refund_addressNameTv.setText(receiver);
                refund_addressNumberTv.setText(receiverPhone);
                refund_addressTv.setText(receiverAddress);
            } else {
                afterservice_writeLogisticsTv.setVisibility(View.GONE);
            }
            if (statusValue.equals("1")) {
                afterservice_cancelTv.setVisibility(View.VISIBLE);
            } else {
                afterservice_cancelTv.setVisibility(View.GONE);
            }
        } else {
            refund_bottomLayout.setVisibility(View.GONE);
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0) {
            if (data != null) {
                if (adapter != null) {
                    adapter.clear();
                }
                presenter.getInfo(packageSn);
            }
        }
    }
}
