package kz.arta.synergy.workflow.mobile.android.forms.general.components.users.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import kz.arta.synergy.workflow.mobile.android.R;
import kz.arta.synergy.workflow.mobile.android.common.utils.Fonts;
import kz.arta.synergy.workflow.mobile.android.forms.general.components.users.model.PositionModel;

/**
 * Created by neox on 05.04.16.
 * Адаптер для должностей
 */
public class PositionsChooserAdapter extends ArrayAdapter<PositionModel> {

    /**
     * Список должностей
     */
    private List<PositionModel> positions;

    /**
     * Контекст
     */
    private Context context;

    /**
     * Конструктор адаптера должностей
     *
     * @param context   контекст
     * @param positions список должностей
     */
    public PositionsChooserAdapter(Context context, List<PositionModel> positions) {
        super(context, R.layout.users_chooser_activity, positions);
        this.context = context;
        this.positions = positions;
    }

    @Override
    public View getView(int position, View someView, ViewGroup arg2) {

        LayoutInflater inflater = LayoutInflater.from(context);

        if (someView == null) {
            someView = inflater.inflate(R.layout.item_users_list, arg2, false);
        }

        TextView userName = (TextView) someView.findViewById(R.id.item_users_name);
        userName.setText(positions.get(position).getElementName());
        userName.setTypeface(Fonts.getRoman(context));

        TextView userPosition = (TextView) someView.findViewById(R.id.item_users_position);
        userPosition.setTypeface(Fonts.getRoman(context));
        userPosition.setText(positions.get(position).getDepartmentName());

        ImageView checkerBackground = (ImageView) someView.findViewById(R.id.item_users_checkbox_image);
        ImageView checker = (ImageView) someView.findViewById(R.id.item_users_checker_image);

        checker.setVisibility(View.GONE);
        checkerBackground.setVisibility(View.GONE);

        someView.setBackgroundColor(context.getResources().getColor((positions.get(position).isChecked()
                ? R.color.selected_item_list_color : android.R.color.transparent)));

        return someView;
    }
}