RegistroPage.xaml.cs

using System;
using System.Collections.Generic;
using Microsoft.Maui.Storage;

namespace DiarioBienestar
{
    public partial class RegistroPage : ContentPage
    {
        private List<RegistroDiario> registros;

        public RegistroPage()
        {
            InitializeComponent();
            registros = new List<RegistroDiario>();
            activitySlider.ValueChanged += OnSliderValueChanged;
            progresoSemanal.Progress = activitySlider.Value / 10;
        }

        private void OnSliderValueChanged(object? sender, ValueChangedEventArgs e)
        {
            // Actualiza el progreso en base al valor del slider
            progresoSemanal.Progress = e.NewValue / 10;
        }

        private void OnGuardarClicked(object sender, EventArgs e)
        {
            var nuevoRegistro = new RegistroDiario
            {
                Fecha = datePicker.Date,
                Nota = editorNota.Text,  
                NivelActividad = (int)activitySlider.Value,
                NivelEnergia = (int)energyStepper.Value
            };

            registros.Add(nuevoRegistro);
            GuardarRegistros();
            DisplayAlert("Éxito", "Registro guardado con éxito", "OK");
        }

        private void OnEnergyStepperValueChanged(object sender, ValueChangedEventArgs e)
        {
            // Actualiza la etiqueta con el valor del stepper
            energyValueLabel.Text = $"{e.NewValue}";
        }

        private void GuardarRegistros()
        {
            // Convierte la lista a JSON y guarda en preferencias
            var json = System.Text.Json.JsonSerializer.Serialize(registros);
            Preferences.Set("registrosDiarios", json);
        }

        protected override void OnAppearing()
        {
            base.OnAppearing();
            CargarRegistros();
        }

        private void CargarRegistros()
        {
            // Carga la lista de registros desde preferencias
            if (Preferences.ContainsKey("registrosDiarios"))
            {
                var json = Preferences.Get("registrosDiarios", string.Empty);
                registros = System.Text.Json.JsonSerializer.Deserialize<List<RegistroDiario>>(json) ?? new List<RegistroDiario>();
            }
        }
    }

    
}