using System; using System.Windows; namespace AxCopilot.Views; public sealed class TranscriptVisualItem { private readonly Func? _factory; private readonly Action? _onMaterialized; private UIElement? _element; public TranscriptVisualItem(string key, UIElement element) { Key = key; _element = element; } public TranscriptVisualItem(string key, Func factory, Action? onMaterialized = null) { Key = key; _factory = factory; _onMaterialized = onMaterialized; } public string Key { get; } public bool IsMaterialized => _element != null; public UIElement? Element => _element; public UIElement GetOrCreateElement() { if (_element != null) return _element; if (_factory == null) throw new InvalidOperationException("Transcript visual factory is not available."); _element = _factory(); _onMaterialized?.Invoke(_element); return _element; } }