using System;
using UnityEngine;
namespace NightclubArcadia.UI
{
///
/// Owns the two independent UI state flags — dialogue active and menu open —
/// and raises so HUD, camera framing, and panels
/// can derive their visibility from a single source of truth.
///
public sealed class UIStateController : MonoBehaviour
{
public static UIStateController Instance { get; private set; }
public bool IsDialogueActive { get; private set; }
public bool IsMenuOpen { get; private set; }
/// Raised after any state change. Subscribers derive their own visibility.
public event Action StateChanged;
void Awake()
{
if (Instance != null && Instance != this)
{
Debug.LogError($"[{nameof(UIStateController)}] Duplicate instance on '{name}'. Destroying this component.", this);
Destroy(this);
return;
}
Instance = this;
}
void OnDestroy()
{
if (Instance == this)
{
Instance = null;
}
}
public void SetDialogueActive(bool value)
{
if (IsDialogueActive == value)
{
return;
}
IsDialogueActive = value;
StateChanged?.Invoke();
}
public void SetMenuOpen(bool value)
{
if (IsMenuOpen == value)
{
return;
}
IsMenuOpen = value;
StateChanged?.Invoke();
}
}
}