package com.dbs.dbsec.activity.activityEvent;

import android.content.Context;
import android.util.Log;

import com.dbs.dbsec.activity.ConsentActivity;
import com.dbs.dbsec.httpTask.CallBack;
import com.dbs.dbsec.httpTask.ParseJsonData;
import com.dbs.dbsec.model.PatientInfoVO;
import com.dbs.dbsec.model.PatientListVO;
import com.dbs.dbsec.util.Common;
import com.dbs.dbsec.util.ConsentConfig;

import java.util.ArrayList;
import java.util.HashMap;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

public class CenterMenu {
  private static final String TAG = CenterMenu.class.getSimpleName();
  private AppCompatActivity mActivity;
  private Context mContext;
  private ConsentActivity instance;
  private LinearLayoutManager linearLayoutManager;

  public PatientInfoVO patientInfoVO = null;


  public CenterMenu(Context mContext, AppCompatActivity mActivity) {
    this.mActivity = mActivity;
    this.mContext = mContext;
    this.instance = (ConsentActivity) mContext;
  }

  public void getPatientInfo(HashMap<String, String> mData) {

    CallBack callBack = new CallBack() {
      @Override
      public void result(final String result) {
        Log.e(TAG, "getPatientInfo -- > " + result);
        mActivity.runOnUiThread(new Runnable() {
          @Override
          public void run() {
            ArrayList<HashMap<String, String>> arrayList = Common.parseJSON(mContext, result);
            String code = arrayList.get(0).get("code");

            if (!code.equals("00")) {
              stop();
            } else {
              patientInfoVO = ParseJsonData.getInstance(mContext).getPatientInfo(arrayList);
              setPatientInfo();
            }
          }
        });
      }

      @Override
      public void stop() {
        instance.dismissProgress();
      }

      @Override
      public void error() {

      }
    };

    if (Common.checkNetwork(mContext) == true) {
      instance.showProgress();
      Common.callHttp(mContext, ConsentConfig.GET_PATIENT_INFO, mData, callBack);
    } else {
      instance.dismissProgress();
      Common.networkErrorAlert(mActivity);
    }
  }

  private void setPatientInfo() {
    instance.dismissProgress();

    String pid = patientInfoVO.getPid();
    String patientName = patientInfoVO.getPatientName();
    String sa          = patientInfoVO.getSa();
    String juminNo     = patientInfoVO.getJuminNo();
    String inDd        = patientInfoVO.getInDd();
    String mainDrName  = patientInfoVO.getMainDrName();
    String dxNm        = patientInfoVO.getDxNm();
    String alert       = patientInfoVO.getGbn();

    String patientInfo = pid + " " + patientName + " " + sa + " " + juminNo.substring(0, 6);

    instance.tvPatientInfo.setText(patientInfo);
    instance.tvAdmissionDay.setText(inDd);
    instance.tvChargeDoctor.setText(mainDrName);
    instance.tvDiagnosisName.setText(dxNm);
    instance.tvPatientAlert.setText(alert);
  }

  public void clearPatientInfo() {
    patientInfoVO = null;
    instance.tvPatientInfo.setText("");
    instance.tvAdmissionDay.setText("");
    instance.tvChargeDoctor.setText("");
    instance.tvDiagnosisName.setText("");
    instance.tvPatientAlert.setText("");


//    if (instance.consentCenterAdaper != null) {
//
//      instance.consentCenterAdaper.arrayList.clear();
//      instance.consentCenterAdaper.notifyDataSetChanged();
//      instance.consentCenterAdaper = null;
//
//      Log.e(TAG, "instance.consentCenterAdaper -- > " + instance.consentCenterAdaper);
//    }
  }




}
