@using Hcs.WebApp.Services
@using Newtonsoft.Json

@inject RegistryService RegistryService

<RadzenTextArea @bind-Value="@content" Style="width: 370px; height:500px; resize: none; display: block; margin-left: auto; margin-right: auto;" ReadOnly="true" />

@code {
    string? content;

    [Parameter]
    public required RegistryElement RegistryElement { get; set; }

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        if (string.IsNullOrEmpty(RegistryElement.Json))
        {
            RegistryElement.Json = await RegistryService.GetRegistryElementJsonAsync(RegistryElement.Id);
        }

        if (!string.IsNullOrEmpty(RegistryElement.Json))
        {
            content = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(RegistryElement.Json!), Formatting.Indented);
        }
    }
}
