using UnityEngine;

namespace Assets.Source.Content.UI.Components
{
    public class OffsetForSmallAspect : MonoBehaviour
    {
        public Vector2 Offset;
        public RectTransform RectTransform;
        public float MinRatio = 0.48f;

        private Vector2 _initPos;

        void Awake()
        {
            _initPos = RectTransform.anchoredPosition;
        }

        void Reset()
        {
            RectTransform = GetComponent<RectTransform>();
        }

        void OnEnable()
        {
            var offset = Vector2.zero;
            if ((float)Screen.width / Screen.height < MinRatio)
                offset = Offset;
            RectTransform.anchoredPosition = _initPos + offset;
        }
    }
}
