@namespace Connected.Components
@implements IDisposable
@inherits UIComponent

<tr class="@Classname" @onclick="@OnRowClicked" @attributes="@CustomAttributes">
    @if (IsEditable && ((Context?.Table.EditButtonPosition.DisplayEditButtonAtStart() == true && Context?.Table.EditTrigger == TableEditTrigger.EditButton) || Context?.Table.ApplyButtonPosition.DisplayApplyButtonAtStart() == true))
    {
        @* Add datalabel as a placeholder to avoid jumps on small viewports *@
        <Td DataLabel="&nbsp;" Class="py-3">
            @if (Context?.Table.EditTrigger == TableEditTrigger.EditButton && !object.ReferenceEquals(Context?.Table._editingItem, Item) && (!Context?.Table.ReadOnly ?? false) && Context?.Table.EditButtonPosition.DisplayEditButtonAtStart() == true)
            {
                @if (Context?.Table.EditButtonContent != null)
                {
                    @Context?.Table.EditButtonContent(new EditButtonContext(StartEditingItem, Context.EditButtonDisabled(Item)))
                }
                else
                {
                    <IconButton Size="@Size.Small" Icon="@Icons.Outlined.Edit" Class="pa-0" OnClick="StartEditingItem" Disabled="Context.EditButtonDisabled(Item)" />
                }
            }
            else if (object.ReferenceEquals(Context?.Table._editingItem, Item) && (!Context?.Table.ReadOnly ?? false) && Context?.Table.ApplyButtonPosition.DisplayApplyButtonAtStart() == true)
            {
                <div style="display: flex;">
                    <Tooltip Text="@Context.Table.CommitEditTooltip">
                        <IconButton Class="pa-0" Icon="@Context.Table.CommitEditIcon" OnClick="FinishEdit" Size="@Size.Small" Disabled="@(!(Context?.Table.Validator?.IsValid ?? false))" />
                    </Tooltip>
                    @if (Context.Table.CanCancelEdit)
                    {
                        <Tooltip Text="@Context.Table.CancelEditTooltip">
                            <IconButton Class="pa-0 ml-4" Icon="@Context.Table.CancelEditIcon" OnClick="CancelEdit" Size="@Size.Small" />
                        </Tooltip>
                    }
                </div>
            }
        </Td>
    }
    @if (IsExpandable || IsCheckable)
    {
        <Element HtmlTag="@("Td")" Class="table-cell">
            <div class="d-flex" style="@ActionsStylename">
                @if (IsCheckable)
                {
                    <CheckBox @bind-Checked="IsChecked" StopClickPropagation="true" Class="table-cell-checkbox"></CheckBox>
                }
            </div>
        </Element>
    }
    @ChildContent
    @if (IsEditable && ((Context?.Table.EditButtonPosition.DisplayEditButtonAtEnd() == true && Context?.Table.EditTrigger == TableEditTrigger.EditButton) || Context?.Table.ApplyButtonPosition.DisplayApplyButtonAtEnd() == true))
    {
        @* Add datalabel as a placeholder to avoid jumps on small viewports *@
        <Td DataLabel="&nbsp;" Class="py-3">
            @if (Context?.Table.EditTrigger == TableEditTrigger.EditButton && !object.ReferenceEquals(Context?.Table._editingItem, Item) && (!Context?.Table.ReadOnly ?? false) && Context?.Table.EditButtonPosition.DisplayEditButtonAtEnd() == true)
            {
                @if (Context?.Table.EditButtonContent != null)
                {
                    @Context?.Table.EditButtonContent(new EditButtonContext(StartEditingItem, Context.EditButtonDisabled(Item)))
                }
                else
                {
                    <IconButton Size="@Size.Small" Icon="@Icons.Outlined.Edit" Class="pa-0" OnClick="StartEditingItem" Disabled="Context.EditButtonDisabled(Item)" />
                }
            }
            else if (object.ReferenceEquals(Context?.Table._editingItem, Item) && (!Context?.Table.ReadOnly ?? false) && Context?.Table.ApplyButtonPosition.DisplayApplyButtonAtEnd() == true)
            {
                <div style="display: flex;">
                    <Tooltip Text="@Context.Table.CommitEditTooltip">
                        <IconButton Class="pa-0" Icon="@Context.Table.CommitEditIcon" OnClick="FinishEdit" Size="@Size.Small" Disabled="@(!(Context?.Table.Validator?.IsValid ?? false))" />
                    </Tooltip>
                    @if (Context.Table.CanCancelEdit)
                    {
                        <Tooltip Text="@Context.Table.CancelEditTooltip">
                            <MudIconButton Class="pa-0 ml-4" Icon="@Context.Table.CancelEditIcon" OnClick="CancelEdit" Size="@Size.Small" />
                        </Tooltip>
                    }
                </div>
            }
        </Td>
    }
</tr>


