@using AuthorBuddy.Web.Models @inject IProjectService ProjectService
@foreach (var cat in _allCategories) { var isActive = (Current & cat) == cat; var disabled = _disabledCategories.Contains(cat); }
@code { private static readonly FileCategory[] _allCategories = new[] { FileCategory.Character, FileCategory.Exposee, FileCategory.Fact, FileCategory.Document }; private HashSet _disabledCategories = new(); [Parameter] public FileCategory Current { get; set; } [Parameter] public int ProjectId { get; set; } [Parameter] public string FilePath { get; set; } = string.Empty; [Parameter] public EventCallback OnCategoryChanged { get; set; } protected override void OnParametersSet() { UpdateDisabled(); } private void UpdateDisabled() { _disabledCategories.Clear(); foreach (var cat in _allCategories) { if (cat == Current) continue; var combined = Current | cat; if (!FileCategoryHelper.IsValid(combined)) _disabledCategories.Add(cat); } } private async Task ToggleCategory(FileCategory cat) { if (_disabledCategories.Contains(cat)) return; var newCategory = Current.HasFlag(cat) ? Current & ~cat : Current | cat; if (!FileCategoryHelper.IsValid(newCategory)) return; await ProjectService.SetFileCategoryAsync(ProjectId, FilePath, newCategory); await OnCategoryChanged.InvokeAsync(newCategory); } private static string CategoryName(FileCategory cat) => cat switch { FileCategory.Character => "Charakter", FileCategory.Exposee => "Exposé", FileCategory.Fact => "Fakt", FileCategory.Document => "Dokument", _ => "" }; private static string CategoryIcon(FileCategory cat) => cat switch { FileCategory.Character => "👤", FileCategory.Exposee => "📋", FileCategory.Fact => "📌", FileCategory.Document => "📄", _ => "" }; }