@using AliasVault.ImportExport.Models
@using AliasVault.ImportExport.Importers
@using Microsoft.Extensions.Localization
@using System.Text
@inject NavigationManager NavigationManager
@inject GlobalNotificationService GlobalNotificationService
@inject IStringLocalizerFactory LocalizerFactory
@inject ILogger<ImportServiceEdge> Logger

<ImportServiceCard
    ServiceName="Edge"
    Description="@Localizer["EdgeDescription"]"
    LogoUrl="img/importers/edge.svg"
    AcceptedFileExtensions="AcceptedExtensions"
    ProcessFileCallback="ProcessFile">
    <p class="text-gray-700 dark:text-gray-300 mb-4">@Localizer["EdgeInstructionsPart1"]</p>
    <p class="text-gray-700 dark:text-gray-300 mb-4">@Localizer["EdgeInstructionsPart2"]</p>
</ImportServiceCard>

@code {
    private IStringLocalizer Localizer => LocalizerFactory.Create("Components.Main.Settings.ImportExport.ImportServices", "AliasVault.Client");
    private static readonly string[] AcceptedExtensions = new[] { ".csv" };

    private static async Task<ImportFileResult> ProcessFile(string filename, byte[] fileBytes)
    {
        var fileContents = Encoding.UTF8.GetString(fileBytes);
        return await EdgeImporter.ImportFromCsvAsync(fileContents);
    }
}
