package com.maxmoney.maxcddconsole.Adapter;


import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.maxmoney.maxcddconsole.Activity.ApproveActivity;
import com.maxmoney.maxcddconsole.Activity.ApproveCustomerClickActivity;
import com.maxmoney.maxcddconsole.Connectivity.BasedUrl;
import com.maxmoney.maxcddconsole.R;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;

public class ApproveUserAdapter extends BaseAdapter {

    private ArrayList<Map<String, String>> data = null;
    private Context context = null;
    private LayoutInflater inflater;

    private class ViewHolder {
        TextView tv1;
        TextView tv2;
        TextView tv3;
    }

    public ApproveUserAdapter(Context context, ArrayList<Map<String, String>> data) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return (data == null) ? 0 : data.size();
    }

    @Override
    public Object getItem(int position) {
        return (data == null) ? null : data.get(position);
    }

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

    @Override
    public boolean isEnabled(int position) {
        return true;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view = convertView;
        final ViewHolder holder;

        if (view == null) {
            inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.list_approve_user, null);

            holder = new ViewHolder();

            holder.tv1 = view.findViewById(R.id.textView_idNo);
            holder.tv2 = view.findViewById(R.id.textView_email);
            holder.tv3 = view.findViewById(R.id.textView_name);

            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.tv1.setText(data.get(position).get("msg1"));
        holder.tv2.setText(data.get(position).get("msg2"));
        holder.tv3.setText(data.get(position).get("msg3"));

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent next = new Intent(context.getApplicationContext(), ApproveCustomerClickActivity.class);
                next.putExtra("session", ApproveActivity.session);
                next.putExtra("email",data.get(position).get("msg2"));
                next.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(next);

            }
        });

        return view;
    }

    public void refreshData(ArrayList<Map<String, String>> newData) {
        this.data = newData;
        this.notifyDataSetChanged();
    }
}