import 'package:flutter/material.dart';
import 'package:flut/flut/runtime.dart';
import 'package:flut/flut/object.dart';
import 'package:flut/flutter/material/color_scheme.dart';
import 'package:flut/flutter/material/text_theme.dart';

class FlutThemeData extends FlutImmutableObject {
  final ThemeData themeData;

  const FlutThemeData(this.themeData) : super('ThemeData');

  @override
  Map<String, dynamic> flutEncode() {
    final result = flutBaseProps();
    result['useMaterial3'] = themeData.useMaterial3;
    result['colorScheme'] = FlutColorScheme(themeData.colorScheme).flutEncode();
    result['textTheme'] = FlutTextTheme(themeData.textTheme).flutEncode();
    return result;
  }

  static ThemeData? flutDecode(FlutRuntime runtime, Map<String, dynamic> data) {
    return ThemeData(
      useMaterial3: runtime.unpackOptionalField<bool>(data, 'useMaterial3'),
      colorScheme: runtime.unpackOptionalField<ColorScheme>(
        data,
        'colorScheme',
      ),
      colorSchemeSeed: runtime.unpackOptionalField<Color>(
        data,
        'colorSchemeSeed',
      ),
      textTheme: runtime.unpackOptionalField<TextTheme>(data, 'textTheme'),
    );
  }
}
