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

/// <summary>
/// опт
/// </summary>
public class ZonesEditorController : MonoBehaviour
{
    public Dictionary<uint, Zone> Zones = new Dictionary<uint, Zone>();
    //public class Zone
    //{

    //}

        
    // Start is called before the first frame update
    void Start()
    {
        
    }

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

    public Zone CreateZone(uint location_id)
    {
        var z = new Zone { 
            id = Convert.ToUInt32(4000000000 + Zones.Count), 
            location_id = location_id,
            name = $"Зона {Zones.Count +1}"
        };
        AddZone(z);

        return z;
    }

    public void EditZone()
    {

    }

    /// <summary>
    /// добавление зоны
    /// </summary>
    /// <param name="Dialog"></param>
    /// <param name="location"></param>
    /// <param name="ZonesScroll"></param>
    /// <param name="z"></param>
    public void AddZone(Zone z)
    {
        var zone = Instantiate(Resources.Load("GameObjects/Zone", typeof(GameObject))) as GameObject;
        zone.transform.SetParent(transform);
        var zoneController = zone.GetComponent<ZoneController>();
        zoneController.Rename($"Zone_{Zones.Count + 1}", z.name);

        if (z != null)
        {
            zone.transform.position = new Vector3(z.start_height, 1, z.start_width);
            zone.transform.localScale = new Vector3(z.end_height, 1, z.end_width);
        }
    }

    public void DeleteZone(uint id)
    {
        Destroy(Zones[id].go);
        Destroy(Zones[id].buttons);
        Zones.Remove(id);
    }    
}
