using UnityEngine.UI;
using UnityEngine;

namespace InterfaceOff
{
    public class WindowComponents : MonoBehaviour
    {
        [field: SerializeField] public Image WindowImage { get; private set; }
        [field: SerializeField] public RectTransform TopBarRectTransform { get; private set; }
        [field: SerializeField] public RectTransform RectTransform { get; private set; }
        [field: SerializeField] public RectTransform CloseButtonRectTransform { get; private set; }
        [field: SerializeField] public Text InfoText { get; private set; }

        public Rect Rect => new
        (
            RectTransform.position.x - RectTransform.rect.width / 2,
            RectTransform.position.y - RectTransform.rect.height / 2,
            RectTransform.rect.width,
            RectTransform.rect.height
        );

        public void SetWidth(float width)
        {
            RectTransform.sizeDelta = new Vector2(width, RectTransform.sizeDelta.y);
            
            WindowImage.rectTransform.sizeDelta = new Vector2(width, 200);
            TopBarRectTransform.sizeDelta = new Vector2(width, 40);

            CloseButtonRectTransform.anchoredPosition = new Vector2(width / 2 - 20, 0);
            InfoText.rectTransform.sizeDelta = new Vector2(width - 40, 30);
        }
    }
}