import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

/// Widget that handles Bluetooth pedal and keyboard shortcuts for page turning.
///
/// Listens for arrow key presses and invokes the appropriate callback:
/// - Arrow Down/Right: Turn page forward
/// - Arrow Up/Left: Turn page backward
class PedalShortcuts extends StatelessWidget {
  final Widget child;
  final VoidCallback onPageForward;
  final VoidCallback onPageBackward;

  const PedalShortcuts({
    super.key,
    required this.child,
    required this.onPageForward,
    required this.onPageBackward,
  });

  @override
  Widget build(BuildContext context) {
    return CallbackShortcuts(
      bindings: _buildBindings(),
      child: Focus(autofocus: true, child: child),
    );
  }

  Map<ShortcutActivator, VoidCallback> _buildBindings() {
    return {
      // Forward navigation
      const SingleActivator(LogicalKeyboardKey.arrowDown): onPageForward,
      const SingleActivator(LogicalKeyboardKey.arrowRight): onPageForward,

      // Backward navigation
      const SingleActivator(LogicalKeyboardKey.arrowUp): onPageBackward,
      const SingleActivator(LogicalKeyboardKey.arrowLeft): onPageBackward,
    };
  }
}
