// lib/editor/ui/page_nav_shortcuts.dart
//
// Shared keyboard page navigation for PDF / slide / office editors.
// Arrow keys + PageUp/PageDown (+ Home/End when provided).

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

class PreviousPageIntent extends Intent {
  const PreviousPageIntent();
}

class NextPageIntent extends Intent {
  const NextPageIntent();
}

class FirstPageIntent extends Intent {
  const FirstPageIntent();
}

class LastPageIntent extends Intent {
  const LastPageIntent();
}

/// Wraps [child] so ←/→/PageUp/PageDown(/Home/End) drive page changes.
Widget pageNavShortcuts({
  required Widget child,
  required VoidCallback? onPrevious,
  required VoidCallback? onNext,
  VoidCallback? onFirst,
  VoidCallback? onLast,
}) {
  return Focus(
    autofocus: true,
    child: CallbackShortcuts(
      bindings: <ShortcutActivator, VoidCallback>{
        const SingleActivator(LogicalKeyboardKey.arrowLeft): () =>
            onPrevious?.call(),
        const SingleActivator(LogicalKeyboardKey.arrowUp): () =>
            onPrevious?.call(),
        const SingleActivator(LogicalKeyboardKey.pageUp): () =>
            onPrevious?.call(),
        const SingleActivator(LogicalKeyboardKey.arrowRight): () =>
            onNext?.call(),
        const SingleActivator(LogicalKeyboardKey.arrowDown): () =>
            onNext?.call(),
        const SingleActivator(LogicalKeyboardKey.pageDown): () =>
            onNext?.call(),
        if (onFirst != null)
          const SingleActivator(LogicalKeyboardKey.home): onFirst,
        if (onLast != null)
          const SingleActivator(LogicalKeyboardKey.end): onLast,
      },
      child: child,
    ),
  );
}
