using TMPro;
using UnityEngine;

namespace YachtDice.Shop
{
    public class ShopTooltipView : MonoBehaviour
    {
        [SerializeField] private TMP_Text titleText;
        [SerializeField] private TMP_Text descriptionText;
        [SerializeField] private TMP_Text priceText;
        [SerializeField] private RectTransform panelRect;
        [SerializeField] private Vector2 offset = new(10f, -10f);

        public void Show(IShopItem item, RectTransform anchor)
        {
            if (titleText != null) titleText.text = item.DisplayName;
            if (descriptionText != null) descriptionText.text = item.Description;
            if (priceText != null) priceText.text = $"Price: {item.ShopPrice}";

            PositionNear(anchor);
            gameObject.SetActive(true);
        }

        public void Hide()
        {
            gameObject.SetActive(false);
        }

        private void PositionNear(RectTransform anchor)
        {
            if (panelRect == null || anchor == null) return;

            Vector3 worldPos = anchor.position;
            panelRect.position = worldPos + (Vector3)offset;
        }
    }
}
