import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../../constants/colors.dart';
import 'sharedPrefs.dart';

part 'app_settings.g.dart';

@riverpod
class UseMaterial3 extends _$UseMaterial3 {
  @override
  bool build() {
    final bool material3 = SharedPrefs().getValue('material3') ?? true;
    return material3;
  }

  void toggle() {
    SharedPrefs().setValue('material3', !state);
    state = !state;
  }
}

@riverpod
class UseDarkMode extends _$UseDarkMode {
  @override
  bool build() {
    final bool darkMode = SharedPrefs().getValue('darkMode') ?? false;
    return darkMode;
  }

  void toggle() {
    SharedPrefs().setValue('darkMode', !state);
    state = !state;
  }
}

@riverpod
class ColorSeedSelected extends _$ColorSeedSelected {
  @override
  ColorSeed build() {
    final String colorSeed =
        SharedPrefs().getValue('colorSeed') ?? ColorSeed.baseColor.label;
    return ColorSeed.values.firstWhere((element) => element.label == colorSeed);
  }

  void setColorSeed(ColorSeed colorSeed) {
    SharedPrefs().setValue('colorSeed', colorSeed.label);
    state = colorSeed;
  }
}

@riverpod
class ShowPerformanceOverlay extends _$ShowPerformanceOverlay {
  @override
  bool build() {
    return false;
  }

  void toggle() {
    state = !state;
  }
}
