@using AIStudio.Provider
@inherits MSGComponentBase

<div class="d-flex">
    <MudTooltip Text="@T("Shows and hides the confidence card with information about the selected LLM provider.")" Placement="Placement.Top">
        @if (this.Mode is PopoverTriggerMode.ICON)
        {
            <MudIconButton Icon="@Icons.Material.Filled.Security" Class="confidence-icon" Style="@this.LLMProvider.GetConfidence(this.SettingsManager).SetColorStyle(this.SettingsManager)" OnClick="@(() => this.ToggleConfidence())"/>
        }
        else
        {
            <MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.Security" IconClass="confidence-icon" Style="@this.LLMProvider.GetConfidence(this.SettingsManager).SetColorStyle(this.SettingsManager)" OnClick="@(() => this.ToggleConfidence())">
                @T("Confidence")
            </MudButton>
        }
    </MudTooltip>

    <MudPopover Open="@this.showConfidence" AnchorOrigin="Origin.TopLeft" TransformOrigin="Origin.BottomLeft" Style="@this.GetPopoverStyle()" DropShadow="@true" Class="border-solid border-4 rounded-lg">
        <MudCard>
            <MudCardHeader>
                <CardHeaderContent>
                    <MudText Typo="Typo.h5">
                        @T("Confidence Card")
                    </MudText>
                </CardHeaderContent>
            </MudCardHeader>
            <MudCardContent Style="max-height: 50vh; max-width: 35vw; overflow: auto;">
                <MudText Typo="Typo.h6">
                    @T("Description")
                </MudText>
                <MudMarkdown Value="@this.currentConfidence.Description"/>

                @if (this.currentConfidence.Sources.Count > 0)
                {
                    <MudText Typo="Typo.h6">
                        @T("Sources")
                    </MudText>
                    <MudList T="@string">
                        @foreach (var sourceTuple in this.GetConfidenceSources())
                        {
                            <MudListItem Icon="@Icons.Material.Filled.Link" Href="@sourceTuple.Source" Target="_blank" Text="@sourceTuple.Index"/>
                        }
                    </MudList>
                }

                @if (!string.IsNullOrWhiteSpace(this.currentConfidence.Region))
                {
                    <MudText Typo="Typo.h6">
                        @T("Region")
                    </MudText>
                    <MudText Typo="Typo.body1" Class="mb-3">
                        <b>@this.currentConfidence.Region</b>
                    </MudText>
                }

                <MudText Typo="Typo.h6">
                    @T("Confidence Level")
                </MudText>
                <MudText Typo="Typo.body1" Style="@this.GetCurrentConfidenceColor()">
                    <b>@this.currentConfidence.Level.GetName()</b>
                </MudText>
            </MudCardContent>
            <MudCardActions>
                <MudButton Variant="Variant.Filled" OnClick="@(() => this.HideConfidence())">
                    Close
                </MudButton>
            </MudCardActions>
        </MudCard>
    </MudPopover>
</div>