@using AIStudio.Settings.DataModel
@inherits SettingsDialogBase

<MudDialog>
    <TitleContent>
        <PreviewPrototype/>
        <MudText Typo="Typo.h6" Class="d-flex align-center">
            <MudIcon Icon="@Icons.Material.Filled.IntegrationInstructions" Class="mr-2"/>
            @T("Configured Data Sources")
        </MudText>
    </TitleContent>
    <DialogContent>
        <MudJustifiedText Typo="Typo.body1" Class="mb-3">
            @T("You might configure different data sources. A data source can include one file, all files in a directory, or data from your company. Later, you can incorporate these data sources as needed when the AI requires this data to complete a certain task.")
        </MudJustifiedText>

        <MudTable Items="@this.SettingsManager.ConfigurationData.DataSources" Hover="@true" Class="border-dashed border rounded-lg">
            <ColGroup>
                <col style="width: 3em;"/>
                <col/>
                <col style="width: 12em;"/>
                <col style="width: 12em;"/>
                <col style="width: 40em;"/>
            </ColGroup>
            <HeaderContent>
                <MudTh>#</MudTh>
                <MudTh>@T("Name")</MudTh>
                <MudTh>@T("Type")</MudTh>
                <MudTh>@T("Embedding")</MudTh>
                <MudTh>@T("Actions")</MudTh>
            </HeaderContent>
            <RowTemplate>
                <MudTd>@context.Num</MudTd>
                <MudTd>@context.Name</MudTd>
                <MudTd>@context.Type.GetDisplayName()</MudTd>
                <MudTd>@this.GetEmbeddingName(context)</MudTd>
                
                <MudTd>
                    <MudStack Row="true" Class="mb-2 mt-2" Wrap="Wrap.Wrap">
                        <MudIconButton Variant="Variant.Filled" Color="Color.Info" Icon="@Icons.Material.Filled.Info" OnClick="() => this.ShowInformation(context)"/>
                        @if (context.IsEnterpriseConfiguration)
                        {
                            <MudTooltip Text="@T("This data source is managed by your organization.")">
                                <MudIconButton Color="Color.Info" Icon="@Icons.Material.Filled.Business" Disabled="true"/>
                            </MudTooltip>
                        }
                        else
                        {
                            <MudButton Variant="Variant.Filled" Color="Color.Info" StartIcon="@Icons.Material.Filled.Edit" OnClick="() => this.EditDataSource(context)">
                                @T("Edit")
                            </MudButton>
                            @if (this.SettingsManager.ConfigurationData.App.ShowAdminSettings && context is DataSourceERI_V1)
                            {
                                <MudTooltip Text="@T("Export configuration")">
                                    <MudIconButton Variant="Variant.Filled" Color="Color.Info" Icon="@Icons.Material.Filled.Dataset" OnClick="() => this.ExportDataSource(context)"/>
                                </MudTooltip>
                            }
                            <MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="() => this.DeleteDataSource(context)">
                                @T("Delete")
                            </MudButton>
                        }
                    </MudStack>
                </MudTd>
            </RowTemplate>
        </MudTable>

        @if (this.SettingsManager.ConfigurationData.DataSources.Count == 0)
        {
            <MudText Typo="Typo.h6" Class="mt-3">
                @T("No data sources configured yet.")
            </MudText>
        }
        
        <MudMenu EndIcon="@Icons.Material.Filled.KeyboardArrowDown" Label="@T("Add Data Source")" Color="Color.Primary" Variant="Variant.Filled" AnchorOrigin="Origin.CenterCenter" TransformOrigin="Origin.TopLeft" Class="mt-3 mb-6">
            <MudMenuItem OnClick="() => this.AddDataSource(DataSourceType.ERI_V1)">
                @T("External Data (ERI-Server v1)")
            </MudMenuItem>
            <MudMenuItem OnClick="() => this.AddDataSource(DataSourceType.LOCAL_DIRECTORY)">
                @T("Local Directory")
            </MudMenuItem>
            <MudMenuItem OnClick="() => this.AddDataSource(DataSourceType.LOCAL_FILE)">
                @T("Local File")
            </MudMenuItem>
        </MudMenu>
    </DialogContent>
    <DialogActions>
        <MudButton OnClick="@this.Close" Variant="Variant.Filled">
            @T("Close")
        </MudButton>
    </DialogActions>
</MudDialog>