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

/// <summary>
/// Панель зон
/// </summary>
public class LocationZones : MonoBehaviour
{
    public Dictionary<uint, ZoneInfo> ZoneInfos = new Dictionary<uint, ZoneInfo>();
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    /// <summary>
    /// Добавление новой зоны в панель
    /// </summary>
    /// <param name="zone"></param>
    public void AddZone(Zone zone)
    {
        var zone_info = Instantiate(Resources.Load("GameObjects/ZoneInfo", typeof(ZoneInfo))) as ZoneInfo;
        ZoneInfos.Add(zone.id, zone_info);
        zone_info.text.text = zone.name;
        zone_info.zone = zone;        
        zone_info.transform.SetParent(gameObject.GetComponent<ScrollRect>().content.transform);
    }

    /// <summary>
    /// Добавление списка зон
    /// </summary>
    /// <param name="zones"></param>
    public void AddRangeZones(List<Zone> zones) {
        foreach (var z in zones)
            AddZone(z);
    }

    /// <summary>
    /// Удаление зоны
    /// </summary>
    /// <param name="id"></param>
    public void DeleteZone(uint id)
    {
        if (ZoneInfos.ContainsKey(id))
        {
            Destroy(ZoneInfos[id].gameObject);
            ZoneInfos.Remove(id);
        }
    }

    /// <summary>
    /// Удаление всех зон из панели
    /// </summary>
    public void DeleteAllZones()
    {
        foreach (var z in ZoneInfos)
            Destroy(z.Value);
    }

    /// <summary>
    /// Зона пользователя
    /// </summary>
    /// <param name="user_id"></param>
    public void UserPosition(User user, Structure user_pos)
    {
        foreach (var z in ZoneInfos)
        {
            z.Value.UserDetectPosition(user, user_pos);
        }
    }
}
