@using RobotNet10.RobotApp.Shared.DockStation @using RobotNet10.Shared.Enum @using RobotNet10.Shared.Numbers @(IsEditMode ? "Edit" : "Create") Dock Station Config Search Area Marker Entries @for (int i = 0; i < _entries.Count; i++) { var index = i; Marker @(index + 1) @foreach (var type in System.Enum.GetValues()) { @type } Reference Points @for (int j = 0; j < _entries[index].ReferencePoints.Count; j++) { var ptIndex = j; } } Cancel @(IsEditMode ? "Update" : "Create") @code { [CascadingParameter] IMudDialogInstance Dialog { get; set; } = null!; [Parameter] public DockStationConfigDto? Config { get; set; } private bool IsEditMode => Config is not null; private string _stationId = string.Empty; private string _configName = string.Empty; private string _description = string.Empty; private double _x; private double _y; private double _yaw; private double _width; private double _length; private bool _isActive = true; private readonly List _entries = []; protected override void OnInitialized() { if (Config is not null) { _stationId = Config.StationId; _configName = Config.ConfigName ?? string.Empty; _description = Config.Description ?? string.Empty; _x = Config.X; _y = Config.Y; _yaw = Config.Yaw; _width = Config.Width; _length = Config.Length; _isActive = Config.IsActive; _entries.AddRange(Config.MarkerEntries.Select(e => new MarkerEntryModel { MarkerId = e.MarkerId, Type = e.Type, Priority = e.Priority, DeviceId = e.DeviceId, Code = e.Code, ReferencePoints = e.ReferencePoints.Select(p => new Vector2Model { X = p.X, Y = p.Y }).ToList() })); } } private void AddMarkerEntry() { _entries.Add(new MarkerEntryModel { Priority = _entries.Count + 1 }); } private void RemoveMarkerEntry(int index) => _entries.RemoveAt(index); private void AddReferencePoint(int entryIndex) { _entries[entryIndex].ReferencePoints.Add(new Vector2Model()); } private void RemoveReferencePoint(int entryIndex, int ptIndex) { _entries[entryIndex].ReferencePoints.RemoveAt(ptIndex); } private List BuildMarkerEntries() => _entries.Select(e => new DockStationMarkerEntryDto { MarkerId = e.MarkerId ?? string.Empty, Type = e.Type, Priority = e.Priority, DeviceId = e.DeviceId, Code = e.Code, ReferencePoints = e.ReferencePoints.Select(p => new Vector2 { X = p.X, Y = p.Y }).ToList() }).ToList(); private void Submit() { if (IsEditMode) { var request = new UpdateDockStationConfigRequest { StationId = _stationId, ConfigName = _configName, Description = _description, X = _x, Y = _y, Yaw = _yaw, Width = _width, Length = _length, IsActive = _isActive, MarkerEntries = BuildMarkerEntries() }; Dialog.Close(DialogResult.Ok(request)); } else { var request = new CreateDockStationConfigRequest { StationId = _stationId, ConfigName = _configName, Description = _description, X = _x, Y = _y, Yaw = _yaw, Width = _width, Length = _length, IsActive = _isActive, MarkerEntries = BuildMarkerEntries() }; Dialog.Close(DialogResult.Ok(request)); } } private void Cancel() => Dialog.Cancel(); private class MarkerEntryModel { public string? MarkerId { get; set; } public MarkerType Type { get; set; } public int Priority { get; set; } = 1; public string? DeviceId { get; set; } public string? Code { get; set; } public List ReferencePoints { get; set; } = []; } private class Vector2Model { public double X { get; set; } public double Y { get; set; } } }