package com.p3.bewoplaner.page.main;

import com.p3.bewoplaner.R;

import android.app.Activity;
import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

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

/**
 * Created by imarneanu on 2/13/17.
 */
class NavigationMenuAdapter extends ArrayAdapter<String> {
    private final static int IMPRESSUM = 3;

    private Context mContext;
    private String[] mData;
    private static MainNavigation mListener;

    NavigationMenuAdapter(Context context, String[] data, MainNavigation listener) {
        super(context, R.layout.item_nav_list, data);
        mContext = context;
        mData = data;
        mListener = listener;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHolder holder;
        if (view != null) {
            holder = (ViewHolder) view.getTag();
        } else {
            LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
            view = inflater.inflate(R.layout.item_nav_list, parent, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }
        holder.action.setText(mData[position]);
        holder.action.setTextSize(position < IMPRESSUM ?  21.0f : 12.0f);
        holder.action.setTextColor(ContextCompat.getColor(mContext, (position < IMPRESSUM ?
                R.color.colorWhite : R.color.colorImpressum)));
        holder.position = position;
        return view;
    }

    static class ViewHolder {
        @BindView(R.id.nav_action)
        TextView action;
        int position;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }

        @OnClick(R.id.nav_action)
        void actionClicked() {
            switch (position) {
                case 0:
                    mListener.goToContacts();
                    break;
                case 1:
                    mListener.goToProfile();
                    break;
                case 2:
                    mListener.logout();
                    break;
                case 3:
                    mListener.goToImpressum();
                    break;
            }
        }
    }
}
