using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Components;
using TestDialogManager.Interfaces;
using TestDialogManager.Services;

namespace TestDialogManager.Components
{
    public partial class FmDialogManager
    {
        [Inject] public RendererService RendererService { get; set; }
        private readonly Dictionary<Guid, IRenderer> _renderers = new Dictionary<Guid, IRenderer>();

        protected override void OnInitialized()
        {
            RendererService.AddRendererAction = AddDialog;
            RendererService.RemoveRendererAction = RemoveDialog;
        }

        private void AddDialog(IRenderer component)
        {
            _renderers.Add(component.Id, component);
            StateHasChanged();
        }
        private void RemoveDialog(Guid id)
        {
            _renderers.Remove(id);
            StateHasChanged();
        }
    }
}

