@using Iceshrimp.Frontend.Core.Miscellaneous
@using Iceshrimp.Frontend.Core.Services
@using Iceshrimp.Shared.Schemas.Web
@inject MetadataService MetadataService
@TextBody

@code {
    [Parameter] [EditorRequired] public required string?             Text     { get; set; }
    [Parameter]                  public          List<EmojiResponse> Emoji    { get; set; } = [];
    [Parameter]                  public          bool                Simple   { get; set; } = false;
    private                                      MarkupString        TextBody { get; set; }

    protected override async Task OnInitializedAsync()
    {
        if (Text != null)
        {
            var instance = await MetadataService.Instance.Value;
            TextBody = await MfmRenderer.RenderStringAsync(Text, Emoji, instance.AccountDomain, Simple);
        }
    }

    protected override async Task OnParametersSetAsync()
    {
        if (Text != null)
        {
            var instance = await MetadataService.Instance.Value;
            TextBody = await MfmRenderer.RenderStringAsync(Text, Emoji, instance.AccountDomain, Simple);
        }
    }
}