@using FastReport.Utils;
<div class="fr-webreport-outline-node">
    <div class="fr-webreport-outline-text">
        @if (HasChildren)
        {
            <img class="fr-webreport-outline-caret" 
                 src="_content/FastReport.Web/Resources/caret-@(Open ? "down" : "right").svg" 
                 @onclick="OpenChild"/>
        }
        else
        {
            <div class="fr-webreport-outline-caret-blank" />
        }
        <a @onclick="GotoPage">@Cortage.Text</a>
    </div>
    @if (Open && HasChildren)
    {
        <div style="width:100%" />
        <div class="fr-webreport-outline-children" style="display: block">
            <OutlineBase xml="Xml" Top="false" PageChanged="PageChanged" />
        </div>
    }
</div>

@code {
    [Parameter]
    public bool HasChildren { get; set; }

    [Parameter]
    public XmlItem Xml { get; set; }

    [Parameter]
    public (string Text, int Page, float offset) Cortage { get; set; }

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

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

    private void OpenChild(MouseEventArgs e)
    {
        Open = !Open;
    }

    private void GotoPage(MouseEventArgs e)
    {
        PageChanged.InvokeAsync(Cortage.Page);
    }
}
