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

class BtPedalShortcuts extends StatefulWidget {
  final Widget child;
  final VoidCallback? onTurnPageForward;
  final VoidCallback? onTurnPageBackward;

  const BtPedalShortcuts({
    super.key,
    required this.child,
    this.onTurnPageForward,
    this.onTurnPageBackward,
  });

  @override
  State<BtPedalShortcuts> createState() => _BtPedalShortcutsState();
}

class _BtPedalShortcutsState extends State<BtPedalShortcuts> {
  String lastAction = "Press pedal...";

  @override
  Widget build(BuildContext context) {
    return CallbackShortcuts(
      bindings: <ShortcutActivator, VoidCallback>{
        // Shortcuts for page forward
        const SingleActivator(LogicalKeyboardKey.arrowUp):
            widget.onTurnPageForward ?? () => {},
        const SingleActivator(LogicalKeyboardKey.arrowRight):
            widget.onTurnPageForward ?? () => {},

        // Shortcuts for page backward
        const SingleActivator(LogicalKeyboardKey.arrowDown):
            widget.onTurnPageBackward ?? () => {},
        const SingleActivator(LogicalKeyboardKey.arrowLeft):
            widget.onTurnPageBackward ?? () => {},
      },
      child: Focus(autofocus: true, child: widget.child),
    );
  }
}
