@using FoodsharingSiegen.Contracts.Enums
@using FoodsharingSiegen.Shared.Helper
@using System.ComponentModel
@inherits FsBase

@{
    var divClass = $"{CssClass} pc-main shadow border-0";
    if (Prospect is { Complete: true }) divClass += " complete";
    if (Prospect is { Warning: true }) divClass += " warning";
    if (Prospect is { RecordState: RecordState.Archived }) divClass += " deleted";
}

<div class="@divClass">
    <h5 class="mb-2 d-flex">
        <div class="flex-grow-1 d-flex">
            <div>
                @if(string.IsNullOrWhiteSpace(Prospect?.Name))
                {
                    <i class="fa-solid fa-exclamation-triangle text-warning"></i>
                    <doublearrows></doublearrows>
                    
                    <em>»Name fehlt«</em>
                }
                else
                {
                    @Prospect?.Name
                }
            </div>

            <div style="flex-grow: 1;"></div>

            @if (Prospect?.FsId != null && Prospect.FsId != 0)
            {
                    <a href="@(CurrentUser.NetworkLink)/profile/@Prospect?.FsId" target="_blank">
                        <small style="font-size: .9rem;">
                            <i class="fa-solid fa-eye"></i> @Prospect?.FsId
                        </small>
                    </a>
            }
            
        </div>
    </h5>

    @if (!string.IsNullOrWhiteSpace(Prospect?.Memo))
    {
        var alertColor = Prospect?.Warning is true ? Color.Warning : Color.Info;
        var alertIconClass = Prospect?.Warning is true ? "fa-solid fa-triangle-exclamation" : "fa-solid fa-circle-info";

        <Alert Color="alertColor" Visible Class="p-2 mb-1">
            <AlertDescription><i class="@alertIconClass"></i> @Prospect?.Memo</AlertDescription>
        </Alert>
    }

    <div class="interaction-grid mb-3">
        <InteractionRow
            Prospect="Prospect"
            Type="InteractionType.Welcome"
            AllowInteraction="@(StateFilter == ProspectStateFilter.OnBoarding && CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador))"
            AddClick="AddInteraction"
            RemoveClick="@RemoveInteraction"
            ButtonIconClass="fa-solid fa-check"
            IconClass="fa-solid fa-handshake-simple">
        </InteractionRow>

        @if (!AppSettings.DisableStepIn)
        {
            <InteractionRow
                Prospect="Prospect"
                Type="InteractionType.StepInBriefing"
                AllowInteraction="@(StateFilter == ProspectStateFilter.OnBoarding && CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador))"
                AddClick="AddInteraction"
                RemoveClick="@RemoveInteraction"
                ButtonIconClass="fa-solid fa-check"
                IconClass="fa-solid fa-graduation-cap">
            </InteractionRow>
        }

        <InteractionRow
            Prospect="Prospect"
            Type="InteractionType.EinAb"
            AllowInteraction="@(StateFilter == ProspectStateFilter.OnBoarding && CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador))"
            AddClick="AddInteraction"
            RemoveClick="@RemoveInteraction"
            Multiple="true"
            Minimum="3"
            ButtonIconClass="fa-solid fa-plus"
            IconClass="fa-solid fa-basket-shopping">
        </InteractionRow>

        <InteractionRow
            Prospect="Prospect"
            Type="InteractionType.ReleasedForVerification"
            AllowInteraction="@(StateFilter is ProspectStateFilter.OnBoarding or ProspectStateFilter.Verification && CurrentUser.IsInGroup(UserGroup.WelcomeTeam))"
            AddClick="AddInteraction"
            RemoveClick="@RemoveInteraction"
            ButtonIconClass="fa-solid fa-check"
            IconClass="fa-solid fa-id-card">
        </InteractionRow>

        @if (CurrentUser.IsInGroup(UserGroup.Ambassador))
        {
            <InteractionRow
                Prospect="Prospect"
                Type="InteractionType.IdCheck"
                AllowInteraction="@CurrentUser.IsInGroup(UserGroup.Ambassador)"
                AddClick="AddInteraction"
                RemoveClick="@RemoveInteraction"
                ButtonIconClass="fa-solid fa-check"
                IconClass="fa-solid fa-magnifying-glass">
            </InteractionRow>
        }

        @if (StateFilter > ProspectStateFilter.OnBoarding)
        {
            <InteractionRow
                Prospect="Prospect"
                Type="InteractionType.PrintPass"
                AllowInteraction="@CurrentUser.IsInGroup(UserGroup.Ambassador)"
                AddClick="AddInteraction"
                RemoveClick="@RemoveInteraction"
                ButtonIconClass="fa-solid fa-check"
                IconClass="fa-solid fa-id-card">
            </InteractionRow>

            <InteractionRow
                Prospect="Prospect"
                AllowInteraction="@CurrentUser.IsInGroup(UserGroup.Ambassador)"
                Type="InteractionType.Verify"
                AddClick="AddInteraction"
                RemoveClick="@RemoveInteraction"
                ButtonIconClass="fa-solid fa-check"
                IconClass="fa-solid fa-user-check">
            </InteractionRow>
        }
    </div>
    
    <div class="flex-grow-1"></div>

    @if(Prospect?.Images?.Count > 0)
    {
        <div class="text-center mt-3">
        <Badge Color="Color.Info" Style="margin-bottom: 0.5rem; cursor: pointer;" @onclick="OpenVerificationDialogAsync"><i class="fa-solid fa-address-card"></i>-Prüfung möglich</Badge></div>
    }      

    <div class="text-center d-flex justify-content-center gap-2 mt-1">

        <Button
            Color="Color.Secondary"
            Height="Height.Px(35)"
            title="Bearbeiten"
            Clicked="EditProspectAsync"
            Visibility="@(CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador) ? Visibility.Default : Visibility.Invisible)"
        ><i class="fa-solid fa-pen-to-square"></i>
        </Button>


        @if(StateFilter > ProspectStateFilter.OnBoarding) 
        {
            @if(Prospect?.Complete != true)
            {
                <Button
                    Color="Color.Primary"
                    Height="Height.Px(35)"
                    title="Fertigstellen"
                    Clicked="@(() => AddInteraction(InteractionType.Complete))"
                    Visibility="@(CurrentUser.IsInGroup(UserGroup.Ambassador) ? Visibility.Default : Visibility.Invisible)"
                ><i class="fa-solid fa-flag-checkered"></i>
                </Button>
            } else {
                <Button
                    Color="Color.Primary"
                    Height="Height.Px(35)"
                    title="Fertigstellen rückgängig"
                    Clicked="@(() => AddInteraction(InteractionType.Complete))"
                    Visibility="@(CurrentUser.IsInGroup(UserGroup.Ambassador) ? Visibility.Default : Visibility.Invisible)"
                ><i class="fa-solid fa-flag"></i>
                </Button>
            }
        }
        
        <Button
            Color="Color.Info"
            Height="Height.Px(35)"
            title="Identitätsprüfung"
            Clicked="OpenVerificationDialogAsync"
            Visibility="@(CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador) ? Visibility.Default : Visibility.Invisible)"
        ><i class="fa-solid fa-address-card"></i>
        </Button>

        @if (Prospect?.RecordState != RecordState.Archived)
        {
            <Button
                Color="Color.Danger"
                Height="Height.Px(35)"
                title="Archivieren"
                Clicked="ArchiveProspectAsync"
                Visibility="@(CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador) ? Visibility.Default : Visibility.Invisible)"
            ><i class="fa-solid fa-box-archive"></i>
            </Button>
        } 
        else
        {
            <Button
                Color="Color.Success"
                Height="Height.Px(35)"
                title="Wiederherstellen"
                Clicked="RestoreProspectAsync"
                Visibility="@(CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador) ? Visibility.Default : Visibility.Invisible)"
            ><i class="fa-solid fa-recycle"></i>
            </Button>
        }
        
    </div>
    
    <small class="text-center" style="margin-top: .5rem;">Geändert: @Prospect?.Modified?.ToLocalTime()</small>
</div>