import 'dart:io' show Platform;
import 'package:digiplug/features/app_home.dart';
import 'package:digiplug/features/devices/presentation/views/device_placeholder_screen.dart';
import 'package:digiplug/features/login/presentation/views/login.dart';
import 'package:digiplug/features/profile/presentation/views/profile.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'route.dart';

abstract class AppRouter {
  static Route<dynamic> generateRoutes(RouteSettings settings) {
    switch (settings.name) {
      // Rute untuk halaman login
      case loginRoute:
        return getPageRoute(settings: settings, view: const LoginScreen());

      // Rute untuk halaman utama (dashboard)
      case dashboardRoute:
        return getPageRoute(settings: settings, view: const Dashboard());

      // Rute untuk halaman profil
      case profileRoute:
        return getPageRoute(settings: settings, view: const ProfileScreen());

      // Rute placeholder untuk detail perangkat agar tidak error saat di-tap
      case digiPlugDetailRoute:
      case lightRoute:
      case acRoute:
      case smartTvRoute:
        return getPageRoute(
            settings: settings, view: const DevicePlaceholderScreen());

      // Rute default jika tidak ada yang cocok
      default:
        return getPageRoute(
          settings: settings,
          view: Scaffold(
            body: Center(
              child: Text('No route defined for ${settings.name}'),
            ),
          ),
        );
    }
  }

  // Helper untuk membuat PageRoute berdasarkan platform (iOS/Android)
  static PageRoute<dynamic> getPageRoute({
    required RouteSettings settings,
    required Widget view,
  }) {
    return Platform.isIOS
        ? CupertinoPageRoute(settings: settings, builder: (_) => view)
        : MaterialPageRoute(settings: settings, builder: (_) => view);
  }
}
