@model SQLInstance
@{
    var configs = Model.Configuration;
    var data = configs.Data;
}
@functions
{
    string DisplayValue(int val)
    {
        switch (val)
        {
            case int.MaxValue:
                <span title="@int.MaxValue.ToComma()">Int.Max</span>
                break;
            case int.MinValue:
                <span title="@int.MinValue.ToComma()">Int.Min</span>
                break;
            default:
                @val.ToComma()
                break;
        }
        return null;
    }
    string ConfigSection(string title, IEnumerable<SQLInstance.SQLConfigurationOption> options)
    {
        if (options.Any())
        {
            <tbody>
                <tr>
                    <th colspan="5" class="category-row">
                        <h5>@title</h5>
                    </th>
                </tr>
                <tr>
                    <th>Name</th>
                    <th>Description</th>
                    <th>Value</th>
                    <th>Active</th>
                    <th class="text-muted">Default (Min - Max)</th>
                </tr>
            </tbody>
            <tbody>
                @foreach (var c in options)
                {
                    ConfigRow(c);
                }
            </tbody>
        }
        return null;
    }
    void ConfigRow(SQLInstance.SQLConfigurationOption c)
    {
        <tr>
            <td>@c.Name @if(c.IsDyanmic){<span class="good"> (Dynamic)</span>}</td>
            <td>@c.Description</td>
            <td class="text-nowrap@(c.Value != c.ValueInUse ? " text-warning" : null)">@DisplayValue(c.Value)</td>
            <td class="text-nowrap@(!c.IsDefault ? " text-warning" : null)">@DisplayValue(c.ValueInUse)</td>
            <td class="text-nowrap text-muted">@DisplayValue(c.Default) (@DisplayValue(c.Minimum) - @DisplayValue(c.Maximum))</td>
        </tr>
    }
}
<h4 class="modal-title" title="Updated @(configs.LastPoll?.ToRelativeTime())">
    @Model.Name<span class="text-muted">:</span> Configuration
</h4>
@if (data?.Any() ?? false)
{
    <table class="table table-striped table-responsive table-super-condensed table-hover">
        @ConfigSection("Non-Default", data.Where(c => !c.IsDefault))
        @ConfigSection("Defaults", data.Where(c => c.IsDefault && !c.IsAdvanced))
        @ConfigSection("Defaults (Advanced)", data.Where(c => c.IsDefault && c.IsAdvanced))
    </table>
}
else
{
    <div class="no-content">No configuration information available</div>
}