// Copyright (c) MudBlazor 2021
// MudBlazor licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace Connected.Components;
///
/// A section (nav link) inside the MudPageContentNavigation
///
public class PageContentSection
{
private List _children = new();
public int LevelSortingValue { get; private set; } = 0;
public PageContentSection Parent { get; private set; } = null;
///
/// create a new instance with a title and id and level set to zero
///
/// name of the section will be displayed in the navigation
/// id of the section. It will be appending to the current url, if the section becomes active
public PageContentSection(string title, string id) : this(title, id, 0, null)
{
}
///
/// create a new instance with a title and id and level
///
/// name of the section will be displayed in the navigation
/// id of the section. It will be appending to the current url, if the section becomes active
/// The level within the hierachy
/// The parent of the section. null if there is no parent or no hierachy
public PageContentSection(string title, string id, int level, PageContentSection parent)
{
Title = title;
Id = id;
Level = level;
Parent = parent;
if (Parent != null)
{
Parent._children.Add(this);
}
}
public int Level { get; set; }
///
/// The Title of the section. This will be displayed in the navigation
///
public string Title { get; set; }
///
/// Id of the section. It will be appending to the current url, if the section becomes active
///
public string Id { get; set; }
///
/// Indicating if the section is currently in the middle of the viewport
///
public bool IsActive { get; private set; }
protected internal void Activate() => IsActive = true;
protected internal void Deactive() => IsActive = false;
internal void SetLevelStructure(int counter, int diff)
{
LevelSortingValue = counter;
int levelDiff = diff / 10;
int value = counter + levelDiff;
foreach (var item in _children)
{
item.SetLevelStructure(value, levelDiff);
value += levelDiff;
}
}
}