using System;
using System.Drawing;
using System.Text;
using FastReport.Dialog;
using Microsoft.AspNetCore.Components;
using FastReport.Web.Blazor.Export;
using FastReport.Web.Blazor.Components.Internal.Dialog;

namespace FastReport.Web
{
    public partial class Dialog
    {
        internal RenderFragment ProcessDialogs()
        {
            return b =>
            {
                Report report = _webReport.Report;

                if (CurrentForm < report.Pages.Count)
                {
                    DialogPage dialog = report.Pages[CurrentForm] as DialogPage;
                    if (!dialog.ActiveInWeb)
                    {
                        dialog.ActiveInWeb = true;
                        dialog.OnLoad(EventArgs.Empty);
                        dialog.OnShown(EventArgs.Empty);
                    }

                    var context = new RenderContext(b);
                    context.OpenComponent<DialogPageComponent>();
                    context.AddAttribute(nameof(DialogPageComponent.WebReport), _webReport);
                    context.AddAttribute(nameof(DialogPageComponent.dialogPage), dialog);
                    context.CloseComponent();
                }
            };
        }
    }
}
