using Core.SaveLoad;
using UnityEngine;
using AppleHills.Core.Settings;
using Core;
namespace UI.CardSystem.StateMachine.States
{
///
/// Enlarged state for NEW cards - shows "NEW CARD" badge and waits for tap to dismiss.
/// Owns the NewCardBadge as a child GameObject.
///
public class CardEnlargedNewState : AppleState, ICardClickHandler
{
[Header("State-Owned Visuals")]
[SerializeField] private GameObject newCardBadge;
private CardContext _context;
private ICardSystemSettings _settings;
private void Awake()
{
_context = GetComponentInParent();
_settings = GameManager.GetSettingsObject();
}
public override void OnEnterState()
{
// Ensure card front is visible and facing camera
if (_context.CardDisplay != null)
{
_context.CardDisplay.gameObject.SetActive(true);
_context.CardDisplay.transform.localRotation = Quaternion.Euler(0, 0, 0);
}
// Check if we're already enlarged (coming from upgrade flow)
bool alreadyEnlarged = _context.RootTransform.localScale.x >= _settings.NewCardEnlargedScale * 0.9f;
if (!alreadyEnlarged)
{
// Normal flow - enlarge the card
if (_context.Animator != null)
{
_context.Animator.PlayEnlarge(_settings.NewCardEnlargedScale);
}
}
// Show NEW badge
if (newCardBadge != null)
{
newCardBadge.SetActive(true);
}
}
public void OnCardClicked(CardContext context)
{
// Tap to dismiss - shrink back to original scale and transition to revealed state
if (context.Animator != null)
{
context.Animator.PlayShrink(context.OriginalScale, onComplete: () =>
{
context.StateMachine.ChangeState("RevealedState");
});
}
else
{
// Fallback if no animator
context.StateMachine.ChangeState("RevealedState");
}
}
private void OnDisable()
{
// Hide NEW badge when leaving state
if (newCardBadge != null)
{
newCardBadge.SetActive(false);
}
}
}
}