import 'dart:developer';

import 'package:flutter/services.dart';

/// Android-only bridge: MainActivity stashes `widget_open_timetable=true`
/// from the launch Intent extra when a widget is tapped, Dart polls once
/// per app-resume to consume and route. iOS widgets simply launch the app
/// without a navigation hint (no widgetURL set) so this returns `false`
/// there via MissingPluginException.
class WidgetNavigation {
  static const MethodChannel _channel = MethodChannel('eu.mhsl.marianum.widget');

  static Future<bool> consumePendingTimetableTap() async {
    try {
      final raw = await _channel.invokeMethod<bool>('consumePendingNavigation');
      return raw ?? false;
    } on MissingPluginException {
      return false;
    } on PlatformException catch (e) {
      log('WidgetNavigation channel error: $e');
      return false;
    }
  }
}
