@using FoodsharingSiegen.Contracts.Entity
@using FoodsharingSiegen.Contracts.Enums
@using FoodsharingSiegen.Shared.Helper

@inherits FsBase

@{
    var colorClass = "";
    if(Done) colorClass = "interaction--color-done";

    var rowClass = "";
    if (Done) rowClass += " done";
    if (NotNeeded) rowClass += " notneeded";
    if (Alert) rowClass += " fs-alert";
}

@if(!AllowInteraction || Prospect is {Complete: true })
{
    <Button Size="Size.Small" Disabled="true">
        <i class="@ButtonIconClass"></i>
    </Button>
} 
else
{
    @if(Interactions.Count == 0 || Multiple)
    {
        if (Multiple) ButtonIconClass = "fa-solid fa-plus";
        <Button Size="Size.Small" Clicked="@(async () => { if (AddClick != null) await AddClick(Type); })"><i class="@ButtonIconClass" style="color: #64ae24;"></i></Button>
    } else {
        <Button Size="Size.Small" Clicked="@(async () => { await RemoveFirstAsync(Type); })"><i class="fa-solid fa-times" style="color: rgb(153, 0, 0);"></i></Button>
    }
}

<div style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis">
    <div class="@colorClass" style="display: inline-block;"><i class="@IconClass"></i> @Type.Translate(AppSettings)</div>
    
    @if(Interactions.Count > 0)
    {
        <span title="@Interactions.First().User.Memo"> (@Interactions.First().User.Name</span> <span>@Interactions.First().Date.ToShortDateString())</span>
    }
</div>

@if(Multiple && Interactions.Count > 0)
{
    
    @foreach (var interaction in Interactions)
    {
        <div class="d-flex justify-content-end">
            @if ((Prospect is not { Complete: true } || interaction.Type == InteractionType.Complete) && AllowInteraction)
            {
                <a style="display: inline-block;"" href=""><i class="fa-solid fa-square-xmark" @onclick="async () => { if (RemoveClick != null) await RemoveClick.Invoke(interaction.Id); }" @onclick:preventDefault></i></a>
            } else {
                <span>&bull;</span>
            }
        </div>
        <div>
            <div>
                <span title="@interaction.User.Memo">@interaction.User.Name (@interaction.Date.ToShortDateString())</span>
                @if (!string.IsNullOrWhiteSpace(interaction.FeedbackInfo))
                {
                    <span>(<i>@interaction.FeedbackInfo</i>)</span>
                }
            </div>
            @FeedbackBuilder(interaction)
        </div>
    }
}