using System;
using System.Collections.Generic;
using KernelPanic.Data;
using KernelPanic.Meta;
using UnityEngine;
using UnityEngine.TextCore.Text;
using UnityEngine.UIElements;
namespace KernelPanic.UI
{
///
/// Renders banner selection and pull controls for the gacha screen.
///
[Serializable]
public sealed class GachaScreenController
{
private const string SelectedClassName = "selected";
private enum SelectorStep
{
Character,
Equipment,
Confirm
}
private readonly List _bannerRows = new();
private readonly string[] _bannerIds =
{
GachaService.BeginnerBannerId,
GachaService.StandardBannerId,
GachaService.LimitedBannerId
};
private VisualElement _root;
private VisualElement _bannerList;
private VisualElement _bannerDetail;
private VisualElement _selectorOverlay;
private VisualElement _selectorDialog;
private VisualElement _selectorReturnFocus;
private Button _pullHistoryButton;
private VisualElement _pullHistoryOverlay;
private ScrollView _pullHistoryDialog;
private VisualElement _pullHistoryReturnFocus;
private DistroDatabase _distroDatabase;
private PackageDatabase _packageDatabase;
private FontAsset _monospaceFont;
private GachaService _gachaService;
private PlayerCollection _playerCollection;
private EntropyWallet _wallet;
private Func, PullResolutionResult> _resolvePulledDistros;
private Func _claimSelectorChoice;
private Action _onChanged;
private Action _requestRootCreditExchange;
private Action _requestPullCutscene;
private Action _openDistroDetail;
private int _selectedBannerIndex;
private int _pendingPullCount;
private int _pendingMissingTokens;
private SelectorStep _selectorStep;
private DistroDefinition _selectorChosenDistro;
private string _selectorResultText;
private bool _hasOpened;
private string _resultBannerId;
private string _resultText;
private readonly List _resultRewardLines = new();
private readonly List _resultRewardStars = new();
public void Bind(VisualElement root, DistroDatabase database, PackageDatabase packageDatabase, FontAsset artFont, GachaService service, PlayerCollection collection, EntropyWallet entropyWallet, Func, PullResolutionResult> pullResolver, Func claimSelectorChoice, Action changedCallback, Action rootCreditExchangeCallback, Action pullCutsceneCallback, Action distroDetailCallback = null)
{
_root = root;
_distroDatabase = database;
_packageDatabase = packageDatabase;
_monospaceFont = artFont;
_gachaService = service;
_playerCollection = collection;
_wallet = entropyWallet;
_resolvePulledDistros = pullResolver;
_claimSelectorChoice = claimSelectorChoice;
_onChanged = changedCallback;
_requestRootCreditExchange = rootCreditExchangeCallback;
_requestPullCutscene = pullCutsceneCallback;
_openDistroDetail = distroDetailCallback;
_bannerList = root.Q("GachaBannerList");
_bannerDetail = root.Q("GachaBannerDetail");
if (_pullHistoryButton != null) _pullHistoryButton.clicked -= OpenPullHistory;
_pullHistoryButton = root.Q