import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';

import '../../../common/widgets/text_input_dialog.dart';
import '../business/service/morse_service.dart';

class LedScreen extends ConsumerWidget {
  const LedScreen({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final TextEditingController textController = TextEditingController();

    return Center(
      child: SizedBox(
        height: 224,
        child: Card(
          color: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.3),
          elevation: 0,
          margin: const EdgeInsets.all(32),
          child: Padding(
            padding: const EdgeInsets.symmetric(vertical: 20.0),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Container(
                    constraints: const BoxConstraints(maxWidth: 400),
                    child: TextInputDialog(
                      controller: textController,
                      title: 'Enter Morse Code Message',
                      onReturnPress: () {
                        // FocusScope.of(context).unfocus();
                        context.pop();
                      },
                    ),
                  ),
                ),
                const SizedBox(
                  height: 12,
                ),
                ElevatedButton(
                  onPressed: () {
                    MorseService().printMessage(textController.text);
                  },
                  child: const Text("Morse Code"),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
