package com.cygnusa.hyperm.adapter;

import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import com.cygnusa.hyperm.R;
import com.cygnusa.hyperm.wrappers.RootGetAllComparisonModel;


public class CompareComparisionExpandableListAdapter extends BaseExpandableListAdapter {


    private Context _context;
    private RootGetAllComparisonModel comparisonModel;

    public CompareComparisionExpandableListAdapter(Context context, RootGetAllComparisonModel compareModel) {
        this._context = context;
        this.comparisonModel = compareModel;

    }

    @Override
    public int getGroupCount() {
        return this.comparisonModel.getDataModel().getComparisonCategoryList().size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return comparisonModel.getDataModel().getComparisonCategoryList().get(groupPosition).getFields().size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return this.comparisonModel.getDataModel().getComparisonCategoryList().get(0);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return this.comparisonModel.getDataModel().getComparisonCategoryList().get(groupPosition).getFields().get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        //String headerTitle = comparisonModel.getDataModel().getCompareModel().get(0).getCategory().get(groupPosition).getTitle();

        String headerTitle = comparisonModel.getDataModel().getComparisonCategoryList().get(groupPosition).getTitle();

        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_header, null);
        }

        TextView lblListHeader = (TextView) convertView
                .findViewById(R.id.list_header);
        lblListHeader.setTypeface(null, Typeface.BOLD);
        lblListHeader.setText(headerTitle);
        lblListHeader.setSingleLine(true);
        lblListHeader.setVisibility(View.INVISIBLE);


        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {

        final String childText = comparisonModel.getDataModel().getComparisonCategoryList().get(groupPosition).getFields().get(childPosition).getValue();

        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_item, null);
        }

        TextView txtListChild = (TextView) convertView
                .findViewById(R.id.list_item);

        txtListChild.setText(childText);
        txtListChild.setSingleLine(true);

        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
}
