using System.Collections.Generic;
using System.Windows.Forms;
using PolyTrader.Core.Modularity;
namespace PolyTraderSharp.Ui
{
///
/// Sammelt die von Core-App und Modulen registrierten Views und öffnet sie als
/// eigenständige Host-Fenster (Einzelinstanz je View).
///
public class ShellUiHost : IModuleUiHost
{
private readonly List _views = new();
private readonly Dictionary _open = new();
public IReadOnlyList Views => _views;
public void RegisterView(ModuleView view) => _views.Add(view);
public void OpenView(ModuleView view)
{
if (_open.TryGetValue(view.Id, out var existing) && !existing.IsDisposed)
{
if (existing.WindowState == FormWindowState.Minimized)
existing.WindowState = FormWindowState.Normal;
existing.BringToFront();
existing.Activate();
return;
}
var host = new ViewHostForm(view);
host.FormClosed += (_, _) => _open.Remove(view.Id);
_open[view.Id] = host;
host.Show();
}
}
}