using GameAudio = DevilLink2.Presentation.AudioManager;
using DevilLink2.Presentation;
using UnityEngine;
namespace DevilLink2.UI
{
/// Synchronous visibility/input gate. Popup motion and completion callbacks are retired.
[DisallowMultipleComponent]
public sealed class UITransition : MonoBehaviour
{
// Compatibility for existing editor tools. These APIs can no longer enable motion.
public const float EnterSeconds=0,ExitSeconds=0;
public static bool EnablePopupAnimations { get=>false; set{} }
public bool? PopupAnimationOverride => null;
public void SetPopupAnimationOverride(bool? ignored){}
private CanvasGroup group;private Transform content;private bool initialized,inputEnabled=true;
public bool IsShown {get;private set;}
public bool IsTransitioning => false;
public static bool IsVisible(GameObject target){var gate=target?target.GetComponent():null;return gate?gate.IsShown:target&&target.activeSelf;}
public static void Show(GameObject target,bool visible){if(!target)return;var gate=target.GetComponent();if(!gate)gate=target.AddComponent();gate.SetVisible(visible);}
public static void SetInput(GameObject target,bool enabled){if(!target)return;var gate=target.GetComponent();if(gate){gate.inputEnabled=enabled;gate.ApplyInput();}else{var g=target.GetComponent();if(g)g.interactable=enabled;}}
private void Prepare(){if(initialized)return;group=GetComponent();if(!group)group=gameObject.AddComponent();
content=transform.Find("Card");if(!content)content=transform.Find("Border");if(!content)content=transform.Find("RewardCard");
var old=GetComponent();if(old){old.ResetVisual();old.enabled=false;}
initialized=true;
}
public void SetVisible(bool visible){bool first=!initialized;Prepare();bool changed=IsShown!=visible;IsShown=visible;
Normalize();ApplyInput();gameObject.SetActive(visible);
if(!first&&changed&&GetComponent())GameAudio.Sound(visible?AudioCue.UI_Open:AudioCue.UI_Close);
}
private void Normalize(){if(group)group.alpha=1;if(content){content.localScale=Vector3.one;var g=content.GetComponent();if(g)g.alpha=1;}}
private void ApplyInput(){if(!group)return;group.interactable=IsShown&&inputEnabled;group.blocksRaycasts=IsShown;}
private void OnEnable(){if(initialized){Normalize();ApplyInput();}}
private void OnDisable(){if(group){group.alpha=1;group.interactable=false;group.blocksRaycasts=false;}if(content)content.localScale=Vector3.one;}
}
}