@using FastReport.Utils;
@using System;
@using System.Text;


@for (int i = 0; i < xml.Count; i++)
{
    var open = false;

    if (Top && xml.Count == 1)
    {
        open = true;
    }
    var node = xml[i];
    var hasChildren = node.Count > 0;
    (string text, int page, float offset) Cortage = ReadOutlineNode(node);

    <OutlineNode HasChildren="hasChildren" Xml="node" Cortage="Cortage" Open="open" PageChanged="PageChanged"/>
}


@code {
    [Parameter]
    public XmlItem xml { get; set; }

    [Parameter]
    public bool Top { get; set; }

    [Parameter]
    public EventCallback<int> PageChanged { get; set; }


    (string text, int page, float offset) ReadOutlineNode(XmlItem node)
    {

        string text = node.GetProp("Text");
        int page = 0;
        float offset = 0f;

        string s = node.GetProp("Page");
        if (!s.IsNullOrWhiteSpace())
        {
            page = int.Parse(s);
            s = node.GetProp("Offset");
            if (!s.IsNullOrWhiteSpace())
                offset = (float)Converter.FromString(typeof(float), s) /* * PDF_DIVIDER*/;
        }

        return (text, page, offset);
    }

}
