@page "/user/setup" @using AliasVault.Client.Auth.Pages.Setup.Components @inherits AliasVault.Client.Auth.Pages.Base.LoginBase @layout Auth.Layout.EmptyLayout @attribute [AllowAnonymous]

@GetStepTitle(_currentStep)

@if (GetProgressPercentage() > 0) {
} @switch (_currentStep) { case SetupStep.Welcome: break; case SetupStep.TermsAndConditions: break; case SetupStep.Username: break; case SetupStep.Password: break; case SetupStep.Creating: break; }
@if (_currentStep == SetupStep.Password && !string.IsNullOrWhiteSpace(_setupData.Password)) { } else if (_currentStep != SetupStep.Creating) { }
@code { private SetupStep _currentStep = SetupStep.Welcome; private readonly SetupData _setupData = new(); /// /// Determines if the "Continue" button is enabled based on the current step and setup data. /// private bool IsNextEnabled => _currentStep switch { SetupStep.Welcome => true, SetupStep.TermsAndConditions => _setupData.AgreedToTerms, SetupStep.Username => !string.IsNullOrWhiteSpace(_setupData.Username), SetupStep.Password => !string.IsNullOrWhiteSpace(_setupData.Password), _ => false }; /// /// Get the title for the setup step. /// /// The current setup step. /// The title for the setup step. private static string GetStepTitle(SetupStep step) { return step switch { SetupStep.Welcome => "Welcome to AliasVault", SetupStep.TermsAndConditions => "Using AliasVault", SetupStep.Username => "Choose Username", SetupStep.Password => "Set Password", SetupStep.Creating => "Creating Vault", _ => "Setup" }; } /// /// Handles the form submission. /// private async Task HandleSubmit() { if (IsNextEnabled) { await GoNext(); } } /// /// Navigates to the previous step in the setup process. /// private void GoBack() { switch (_currentStep) { case SetupStep.TermsAndConditions: _currentStep = SetupStep.Welcome; break; case SetupStep.Username: _currentStep = SetupStep.TermsAndConditions; break; case SetupStep.Password: _currentStep = SetupStep.Username; break; case SetupStep.Creating: _currentStep = SetupStep.Password; break; } } /// /// Navigates to the next step in the setup process. /// private async Task GoNext() { _currentStep = _currentStep switch { SetupStep.Welcome => SetupStep.TermsAndConditions, SetupStep.TermsAndConditions => SetupStep.Username, SetupStep.Username => SetupStep.Password, SetupStep.Password => SetupStep.Creating, _ => _currentStep }; await JsInteropService.ScrollToTop(); StateHasChanged(); } /// /// Cancels the setup process and navigates to the start page. /// private void CancelSetup() { NavigationManager.NavigateTo("/"); } /// /// Handles the change of the terms and conditions agreement. /// /// True if the terms and conditions are agreed to, false otherwise. private void HandleAgreedToTermsChanged(bool agreed) { _setupData.AgreedToTerms = agreed; StateHasChanged(); } /// /// Enum representing the different steps in the setup process. /// private enum SetupStep { Welcome, TermsAndConditions, Username, Password, Creating } /// /// Data class for storing setup data. /// private sealed class SetupData { public bool AgreedToTerms { get; set; } public string Username { get; set; } = string.Empty; public string Password { get; set; } = string.Empty; } /// /// Calculates the progress percentage based on the current step in the setup process. /// /// The progress percentage as an integer. private int GetProgressPercentage() { return (int)_currentStep * 100 / (Enum.GetValues(typeof(SetupStep)).Length - 1); } }