/**
 * @file React component that wraps children in a named shortcut scope.
 *
 * Activates/deactivates the scope based on the `active` prop and provides
 * scope name via context so child `useShortcut` calls inherit it automatically.
 */

import React from 'react';
import PropTypes from 'prop-types';
import { ShortcutScopeContext } from './ShortcutContext';
import { useShortcutScope } from './useShortcutScope';

/**
 * @param {Object} props
 * @param {string} props.name - Scope name
 * @param {boolean} [props.active=true] - Whether the scope is active
 * @param {React.ReactNode} props.children
 */
export function ShortcutScope({ name, active = true, children }) {
  useShortcutScope(name, active);

  return (
    <ShortcutScopeContext.Provider value={name}>
      {children}
    </ShortcutScopeContext.Provider>
  );
}

ShortcutScope.propTypes = {
  name: PropTypes.string.isRequired,
  active: PropTypes.bool,
  children: PropTypes.node.isRequired,
};
