using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Item : MonoBehaviour {
    public List<Slot> slots = new List<Slot>();
    private Vector3 startPosition;

	public Transform offset_transform;

	public Vector3 offsetVector;

    void Start()
    {
        startPosition = transform.position;
		offsetVector = offset_transform.transform.position - transform.position;
		offset_transform.GetComponent<SpriteRenderer> ().enabled = false;
    }

    void Update()
    {
        //this.rigidbody.velocity
    }

    public void reset()
    {
        slots.Clear();
        this.transform.position = startPosition;

		this.transform.rotation = Quaternion.Euler(new Vector3(0,0,0));
    }

    public Slot getClosestSlot()
    {
        if (slots.Count == 0)
            return null;

        Slot slot = slots[0];
        float smallestDistance = Vector3.Distance(slot.transform.position, this.transform.position);

        float distance;
        foreach (Slot s in slots)
        {
            distance = Vector3.Distance(s.transform.position, this.transform.position);
            if (distance < smallestDistance)
            {
                slot = s;
                smallestDistance = distance;
            }
        }
        return slot;
    }

    public Slot getFarthestSlot()
    {
        if (slots.Count == 0)
            return null;

        Slot slot = slots[0];
        float farthestDistance = Vector3.Distance(slot.transform.position, this.transform.position);

        float distance = 0;
        foreach (Slot s in slots)
        {
            distance = Vector3.Distance(s.transform.position, this.transform.position);
            if (distance > farthestDistance)
            {
                slot = s;
                farthestDistance = distance;
            }
        }
        return slot;
    }
}
