using System;
using Avalonia.Controls;
using Avalonia.Interactivity;
using ClaudeDo.Ui.ViewModels;

namespace ClaudeDo.Ui.Views;

public partial class InteractiveTerminalView : UserControl
{
    public InteractiveTerminalView()
    {
        InitializeComponent();
        TerminalHost.Loaded += OnTerminalHostLoaded;
        DataContextChanged += OnDataContextChanged;
    }

    private void OnDataContextChanged(object? sender, EventArgs e)
    {
        if (DataContext is InteractiveTerminalViewModel vm && TerminalHost.IsLoaded)
            vm.AttachControl(TerminalHost);
    }

    private void OnTerminalHostLoaded(object? sender, RoutedEventArgs e)
    {
        if (DataContext is InteractiveTerminalViewModel vm)
            vm.AttachControl(TerminalHost);
    }
}
