using System;
using Microsoft.AspNetCore.Components.Rendering;
using TestDialogManager.Dialogs;
using TestDialogManager.Interfaces;

namespace TestDialogManager.Renderers
{
    public class FmMessageDialogRenderer : IRenderer
    {
        public Guid Id { get; set; }
        public string HeaderText { get; }
        public string MessageText { get; }
        public DialogButtons DialogButtons { get; }
        public DialogImage DialogImage { get; }
        public bool CloseWhenOverlayClicked { get; }
        public Action<DialogResult> Callback { get; }
        public object Parameter { get; }

        public FmMessageDialogRenderer(Guid id, string messageText, string headerText, DialogButtons dialogButtons,
            DialogImage dialogImage,
            Action<DialogResult> callback, object parameter, bool closeWhenOverlayClicked)
        {
            Console.WriteLine("New FmMessageDialogRenderer Id = " + id);
            Id = id;
            HeaderText = headerText;
            MessageText = messageText;
            DialogButtons = dialogButtons;
            DialogImage = dialogImage;
            Callback = callback;
            Parameter = parameter;
            CloseWhenOverlayClicked = closeWhenOverlayClicked;
        }

        public void Render(RenderTreeBuilder builder)
        {
            builder.OpenComponent(0, typeof(FmMessageDialog));
            builder.SetKey(Id);
            builder.AddAttribute(1, "Id", Id);
            builder.AddAttribute(2, "HeaderText", HeaderText);
            builder.AddAttribute(3, "MessageText", MessageText);
            builder.AddAttribute(4, "DialogButtons", DialogButtons);
            builder.AddAttribute(5, "DialogImage", DialogImage);
            builder.AddAttribute(6, "CloseWhenOverlayClicked", CloseWhenOverlayClicked);
            builder.AddAttribute(7, "Callback", Callback);
            builder.AddAttribute(8, "Parameter", Parameter);
            builder.CloseComponent();
        }
    }
}