import 'package:flutter/material.dart';
import 'package:pharmacy_mobile/pages/add_category.dart';
import 'package:pharmacy_mobile/pages/add_generics.dart';
import 'package:pharmacy_mobile/pages/add_medicine.dart';
import 'package:pharmacy_mobile/pages/add_stock.dart';
import 'package:pharmacy_mobile/pages/add_type.dart';
// import 'package:pharmacy_mobile/auth/auth_gate.dart';
import 'package:pharmacy_mobile/pages/index_page.dart';
import 'package:pharmacy_mobile/pages/list_stocks.dart';
import 'package:pharmacy_mobile/pages/login_page.dart';
import 'package:go_router/go_router.dart';
import 'package:pharmacy_mobile/pages/main_page.dart';
import 'package:pharmacy_mobile/pages/register_page.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

// void main() {
//   runApp(const MyApp());
// }

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  final supUrl = "https://lijihnvjlucyvxfhghqd.supabase.co";
  final supAnonkey =
      "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImxpamlobnZqbHVjeXZ4ZmhnaHFkIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjQ1NjEyODYsImV4cCI6MjA0MDEzNzI4Nn0.N3_FLKm02OdprL9m3P0CzuV8kdbCrrJKaVdtgVR3PSk";

  await Supabase.initialize(
    url: supUrl,
    anonKey: supAnonkey,
  );

  runApp(MyApp());
}

final _router = GoRouter(
  initialLocation: '/',
  routes: [
    GoRoute(
      name: 'index',
      path: '/',
      builder: (context, state) => IndexPage(),
    ),
    GoRoute(
      name: 'login',
      path: '/login',
      builder: (context, state) => LoginPage(),
    ),
    GoRoute(
      name: 'register',
      path: '/register',
      builder: (context, state) => RegisterPage(),
    ),
    GoRoute(
      name: 'main',
      path: '/main',
      builder: (context, state) => MainPage(),
    ),
    GoRoute(
      name: 'addmedicines',
      path: '/addmedicines',
      builder: (context, state) => AddMedicinePage(),
    ),
    GoRoute(
      name: 'addgenerics',
      path: '/addgenerics',
      builder: (context, state) => AddGenericsPage(),
    ),
    GoRoute(
      name: 'addtype',
      path: '/addtype',
      builder: (context, state) => AddTypePage(),
    ),
    GoRoute(
      name: 'addcategory',
      path: '/addcategory',
      builder: (context, state) => AddCategoryPage(),
    ),
    GoRoute(
      name: 'addstock',
      path: '/addstock',
      builder: (context, state) => AddStockPage(),
    ),
    GoRoute(
      name: 'liststocks',
      path: '/liststocks',
      builder: (context, state) => ListStocksPage(),
    ),
  ],
);

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        useMaterial3: true,
      ),
      routerConfig: _router,
    );
  }
}
