package com.dbs.dbsec.activity.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.dbs.dbsec.R;
import com.dbs.dbsec.model.DeptListVO;
import com.dbs.dbsec.model.DoctorListVO;
import com.dbs.dbsec.util.ConsentConfig;

import java.util.ArrayList;

public class DeptSpinnerAdapter  extends BaseAdapter {

  private AppCompatActivity mActivity;
  private ArrayList arrayList;
  private String apiType = "";

  public DeptSpinnerAdapter(AppCompatActivity mActivity, ArrayList arrayList, String apiType) {
    this.mActivity = mActivity;
    this.arrayList = arrayList;
    this.apiType   = apiType;
  }

  @Override
  public int getCount() {
    return arrayList.size();
  }

  @Override
  public Object getItem(int position) {
    return arrayList.get(position);
  }

  @Override
  public long getItemId(int position) {
    return position;
  }

  class ViewHolder {
    public TextView tvTitle;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    ViewHolder holder = null;
    DeptListVO deptListVO = null;
    DoctorListVO doctorListVO = null;
    if (v == null) {
      holder = new ViewHolder();
      v = LayoutInflater.from(parent.getContext()).inflate(R.layout.spinner_layout, parent, false);
      holder.tvTitle = (TextView) v.findViewById(R.id.spinnerTarget);

      v.setTag(holder);
    } else {
      holder = (ViewHolder) v.getTag();
    }

    String textNm = "";
    if (apiType.equals(ConsentConfig.GET_WARD_LIST) || apiType.equals(ConsentConfig.GET_DEPT_LIST)) {
      deptListVO = (DeptListVO) arrayList.get(position);
      textNm = deptListVO.getDeptNm();
    } else {
      doctorListVO = (DoctorListVO) arrayList.get(position);
      textNm = doctorListVO.getDoctorNm();
    }

    holder.tvTitle.setText(textNm);
    return v;
  }
}
