using UnityEngine;

namespace InterfaceOff
{
    public class CanvasManager : MonoBehaviour
    {
        [field: SerializeField] public RectTransform CanvasRect { get; private set; }
        [field: SerializeField] public Canvas GameCanvas { get; private set; }
        
        public static CanvasManager Instance { get; private set; }

        private void Awake()
        {
            if (DebugUtils.IsNull(Instance))
            {
                Instance = this;
                return;
            }
            
            Debug.LogError("Multiple instances of Canvas Manager have been found");
        }

        public static Vector3 GetRandomPositionOnCanvas()
        {
            Rect rect = Instance.GameCanvas.pixelRect;

            float x = Random.Range(rect.xMin, rect.xMax);
            float y = Random.Range(rect.yMin, rect.yMax);

            return new Vector3(x, y, 0f);
        }
    }
}
