import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:frontend_eccp_mobile/app/core/navigation/app_navigator.dart';
import 'package:frontend_eccp_mobile/app/core/navigation/app_routes.dart';

class NotificationRoutes {
  static Future<void> routeToPage(
    BuildContext context,
    String page,
    Map<String, dynamic>? params,
  ) async {
    log('Routing to page=$page params=$params', name: 'FCM');
    switch (page) {
      case 'setting':
        await AppNavigator.clearAndPush(
          context,
          AppRoutes.settings,
        );
        return;

      case 'berkas':
        final id = params?['id'];

        await AppNavigator.clearAndPush(
          context,
          AppRoutes.berkas,
          onOpened: () async {
            if (id != null) {
              await AppNavigator.push(
                context,
                AppRoutes.berkas,
                extra: {
                  'berkasId': id.toString(),
                },
              );
            }
          },
        );
        return;

      default:
        await AppNavigator.clearAndPush(
          context,
          AppRoutes.home,
        );

        log('Unknown notification page: $page', name: 'FCM');
    }
  }
}
