@namespace Connected.Components
@implements IDisposable
@inherits UIComponent
@typeparam T

@*HEADER:*@
@if (HeaderTemplate != null && GroupDefinition != null)
{
<tr class="@HeaderClassname" @onclick="@OnRowClick" style="@HeaderStyle" @attributes="@CustomAttributes">        
    @if ((GroupDefinition?.IsThisOrParentExpandable ?? false) || (Context?.Table.MultiSelection ?? false))
    {
        <Td>
            <div class="d-flex">
                @if (GroupDefinition.Expandable)
                {
                    <IconButton Class="table-row-expander" Icon="@(IsExpanded ? ExpandIcon : CollapseIcon)" OnClick="@(() => IsExpanded = !IsExpanded)"/>
                }
                else
                {
                    if (GroupDefinition?.IsParentExpandable ?? false)
                    {
                        <div style="@ActionsStylename"></div>
                    }
                }
                @if (IsCheckable)
                {
                    <CheckBox @bind-Checked="IsChecked" Class="table-cell-checkbox"/>
                }
            </div>
        </Td>
    }
    @HeaderTemplate(new TableGroupData<object, T>(GroupDefinition.GroupName, Items.Key, Items.ToList()))
    @if ((Context?.Table.IsEditable ?? false))
    {
        <Td />
    }
</tr>
}
else
{
<TextContent @attributes="@CustomAttributes">@("There aren't any group definition to use with this component.")</TextContent>
}

@if (IsExpanded)
{
    @*CHILDREN:*@
    @if (_innerGroupItems != null && GroupDefinition != null)
    {
        @foreach (var group in _innerGroupItems)
        {
            <TableGroupRow GroupDefinition="GroupDefinition.InnerGroup" Items="@group" IsCheckable="@IsCheckable"
                              HeaderClass="@HeaderClass" HeaderStyle="@HeaderStyle"
                              FooterClass="@FooterClass" FooterStyle="@FooterStyle"
                              HeaderTemplate="@HeaderTemplate" FooterTemplate="@FooterTemplate" T="T" @attributes="@CustomAttributes" />
        }
    }
    else
    {
        @Table?.RenderRows(Items, (GroupDefinition?.Indentation ?? false) ? $"table-row-group-indented-{GroupDefinition?.Level - 1}" : null, GroupDefinition?.IsThisOrParentExpandable ?? false)
    }

    @*FOOTER:*@
    @if (FooterTemplate != null && GroupDefinition != null)
    {
        <tr class="@FooterClassname" @onclick="@OnRowClick" style="@FooterStyle" @attributes="@CustomAttributes">
            @if ((GroupDefinition?.IsThisOrParentExpandable ?? false) || (Context?.Table.MultiSelection ?? false))
            {
                <Td/>
            }
            @FooterTemplate(new TableGroupData<object, T>(GroupDefinition.GroupName, Items.Key, Items.ToList()))
            @if ((Context?.Table.IsEditable ?? false))
            {
                <Td />
            }

        </tr>
    }
}