using System;
using System.Collections.Generic;
using System.ComponentModel;
using InABox.Core;
using InABox.DynamicGrid;

namespace InABox.Wpf;

public abstract class MasterDetailPage<TMaster> : IMasterDetailPage<TMaster>
{
    public event DataModelUpdateEvent? OnUpdateDataModel;

    protected MasterDetailPage(DynamicTabItem tab)
    {
        Tab = tab;
    }
    
    public DynamicTabItem Tab { get; set; }

    public abstract Dictionary<string, object[]>? Selected();

    public IDataModelSource? Refresh(TMaster? master)
    {
        Master = master;
        return Refresh();
    }
    
    protected abstract IDataModelSource? Refresh();
    
    public abstract IDataModelSource? DataModelSource();

    public virtual void CreateToolbarButtons(IPanelHost host)
    {
    }
    
    public TMaster? Master { get; set; }

    protected void UpdateDataModel(string sectionName, DataModel model)
    {
        OnUpdateDataModel?.Invoke(sectionName, model);
    }

    public virtual void Heartbeat(TimeSpan time)
    {
    }

    public virtual void Shutdown(CancelEventArgs? cancel)
    {
    }
}