/// Re-exports [KcAppScope] from the shared `core` package and provides
/// convenience accessors typed to [AppServices].
///
/// This file preserves backward compatibility for existing imports within
/// `kell_web`. New code should use [KcAppScope] from `package:core/core.dart`
/// directly.
library;

import 'package:core/core.dart';
import 'package:flutter/widgets.dart';

import 'app_services.dart';

export 'package:core/core.dart' show KcAppScope;

/// App-specific convenience wrapper around [KcAppScope] for `kell_web`.
///
/// Preserves the original `AppScope.of(context)` and `AppScope.configOf(context)`
/// call sites so existing code continues to work without modification.
///
/// New code should prefer:
/// ```dart
/// KcAppScope.of<AppServices>(context)
/// KcAppScope.configOf<AppServices>(context)
/// ```
class AppScope extends KcAppScope<AppServices> {
  const AppScope({super.key, required super.services, required super.config, required super.child});

  /// Returns the nearest [AppServices] from the widget tree.
  ///
  /// Throws if no [AppScope] ancestor is found.
  static AppServices of(BuildContext context) {
    final scope = context.dependOnInheritedWidgetOfExactType<AppScope>();
    assert(scope != null, 'No AppScope found in the widget tree');
    return scope!.services;
  }

  /// Returns the nearest [KcAppConfig] from the widget tree.
  ///
  /// Throws if no [AppScope] ancestor is found.
  static KcAppConfig configOf(BuildContext context) {
    final scope = context.dependOnInheritedWidgetOfExactType<AppScope>();
    assert(scope != null, 'No AppScope found in the widget tree');
    return scope!.config;
  }
}
