/*
 * Copyright (c) 2016, Aegir Labs LLC. All rights reserved.
 */

package com.aegir.demo.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aegir.demo.R;
import com.aegir.vmms.wayfinding.enums.MapDirectionsIcon;
import com.aegir.vmms.wayfinding.model.MapDirectionStep;

/**
 * View used in ItemAdapter.  Displays a direction step.
 */
public class DirectionItemView extends RelativeLayout {

    // region Fields

    private TextView titleTextView;
    private TextView descriptionTextView;
    private ImageView iconImageView;

    // endregion

    // region Constructors

    /**
     *
     * @param c the activity context
     */
    public DirectionItemView(Context c) {
        this(c, null);
    }

    /**
     *
     * @param context the activity context
     * @param attrs layout attributes
     */
    public DirectionItemView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    /**
     *
     * @param context the activity context
     * @param attrs layout attributes
     * @param defStyle style resource
     */
    public DirectionItemView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        LayoutInflater.from(context).inflate(R.layout.item_view_children, this, true);
        setupChildren();
    }

    // endregion

    // region Public Methods

    /**
     *
     * @param parent the parent view to use for inflation
     * @return a new direction item view
     */
    public static DirectionItemView inflate(ViewGroup parent) {
        DirectionItemView itemView = (DirectionItemView)LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_view, parent, false);
        return itemView;
    }

    /**
     *
     * @param step the MapDirectionStep that this object displays
     */
    public void setItem(MapDirectionStep step) {
        titleTextView.setText(step.getInstructions());
        descriptionTextView.setText(step.getDistance());

        if (step.getDirectionIcon() == MapDirectionsIcon.START) {
            iconImageView.setImageResource(R.drawable.icon_start_point);
        } else if (step.getDirectionIcon() == MapDirectionsIcon.END) {
            iconImageView.setImageResource(R.drawable.icon_end_point);
        } else if (step.getDirectionIcon() == MapDirectionsIcon.LEFT) {
            iconImageView.setImageResource(R.drawable.icon_left_turn);
        } else if (step.getDirectionIcon() == MapDirectionsIcon.RIGHT) {
            iconImageView.setImageResource(R.drawable.icon_right_turn);
        } else if (step.getDirectionIcon() == MapDirectionsIcon.ELEVATOR) {
            iconImageView.setImageResource(R.drawable.icon_elevator);
        } else if (step.getDirectionIcon() == MapDirectionsIcon.STAIRS) {
            iconImageView.setImageResource(R.drawable.icon_stairwell);
        } else {
            iconImageView.setImageResource(R.drawable.icon_straight_ahead);
        }
    }

    // endregion

    // region Private methods

    /**
     *
     */
    private void setupChildren() {
        titleTextView = (TextView) findViewById(R.id.tv_title_item);
        descriptionTextView = (TextView) findViewById(R.id.tv_description_item);
        //stepTextView = (TextView) findViewById(R.id.item_directionStep);
        iconImageView = (ImageView) findViewById(R.id.iv_icon_item);
    }

    // endregion
}
