@using Statiq.CodeAnalysis
@using Microsoft.AspNetCore.Html
@using Docs.Extensions
@{
    var isEnum = Document.GetString(CodeAnalysisKeys.SpecificKind) == "Enum";
    IReadOnlyList<IDocument> fields;
    if (isEnum)
    {
        fields = Document.GetDocumentList(CodeAnalysisKeys.Members)?.Where(x => x.GetBool(CodeAnalysisKeys.IsResult) && x.GetString(CodeAnalysisKeys.Kind) == "Field")
            .OrderBy(x => x.Get(CodeAnalysisKeys.ConstantValue) as int? ?? 0)
            .ToList();
    }
    else
    {
        fields = Document.GetDocumentList(CodeAnalysisKeys.Members)?.Where(x => x.GetBool(CodeAnalysisKeys.IsResult) && x.GetString(CodeAnalysisKeys.Kind) == "Field")
            .OrderBy(x => x.GetString(CodeAnalysisKeys.DisplayName))
            .ToList();
    }


    if (fields?.Count > 0)
    {
        <h3>Fields</h3>
        <div class="doc-summary">
            <div>
                <dl>
                    @foreach (var field in fields)
                    {
                        <div>
                            <dt>

                                <div class="flex flex-row">
                                    <div class="w-4/5">
                                        @if (isEnum)
                                        {
                                            @Context.GetTypeLink(field, false)
                                        }
                                        else
                                        {
                                            @field.GetModifiers() @Context.GetTypeLink(field.GetDocument(CodeAnalysisKeys.Type))
                                            @Context.GetTypeLink(field, false)
                                        }
                                    </div>
                                    <div>
                                        @(field.GetBool(CodeAnalysisKeys.HasConstantValue) ? new HtmlString(field.Get(CodeAnalysisKeys.ConstantValue)?.ToString() ?? "null") : new HtmlString(string.Empty))
                                    </div>
                                </div>
                            </dt>
                            <dd>
                                @Html.Raw(field.GetString(CodeAnalysisKeys.Summary))
                            </dd>
                        </div>
                    }
                </dl>
            </div>

        </div>
    }
}