import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
import 'package:qadirneyriz/drawer_navigation_bar.dart';
import 'package:qadirneyriz/models/meetings/meetings_model.dart';
import 'package:qadirneyriz/models/private_meeting/private_meetings_model.dart';
// import 'package:qadirneyriz/models/meetings/meetings_model.dart';
import 'package:qadirneyriz/screens/auth/login_screen.dart';
import 'package:qadirneyriz/screens/auth/login_with_otp_screen.dart';
import 'package:qadirneyriz/screens/auth/otp_screen.dart';
import 'package:qadirneyriz/screens/home/screen.dart';
import 'package:qadirneyriz/screens/meeting/screen.dart';
import 'package:qadirneyriz/screens/meeting_add/screen.dart';
import 'package:qadirneyriz/screens/meeting_add/state.dart';
import 'package:qadirneyriz/screens/meeting_edit/screen.dart';
import 'package:qadirneyriz/screens/meeting_edit/state.dart';
import 'package:qadirneyriz/screens/meeting_summary/screen.dart';
import 'package:qadirneyriz/screens/meeting_summary/state.dart';
import 'package:qadirneyriz/screens/private_meeting_add/screen.dart';
import 'package:qadirneyriz/screens/private_meeting_add/state.dart';
import 'package:qadirneyriz/screens/private_meeting_edit/screen.dart';
import 'package:qadirneyriz/screens/private_meeting_edit/state.dart';
import 'package:qadirneyriz/screens/private_meeting_summary/screen.dart';
import 'package:qadirneyriz/screens/private_meeting_summary/state.dart';
import 'package:qadirneyriz/screens/report/screen.dart';
import 'package:qadirneyriz/screens/report/state.dart';
import 'package:qadirneyriz/splash_screen.dart';

final GoRouter router = GoRouter(
  initialLocation: '/route',
  routes: <GoRoute>[
    GoRoute(
      path: '/navigate/:tab',
      name: 'navigate',
      builder: (context, state) {
        return CustomDrawerNavigation(
          activeTab: int.parse(state.pathParameters["tab"]!),
        );
      },
    ),
    GoRoute(
      path: '/home',
      name: 'home',
      builder: (context, state) {
        return const HomeScreen();
      },
    ),
    GoRoute(
        path: '/route',
        builder: (BuildContext context, GoRouterState state) {
          return const SplashScreen();
        },
        routes: [
          GoRoute(
            path: 'login',
            name: 'login',
            builder: (context, state) {
              return const LoginScreen();
            },
          ),
          GoRoute(
            path: 'loginotp',
            name: 'loginotp',
            builder: (context, state) {
              return const LoginWithOtpScreen();
            },
          ),
          GoRoute(
            path: 'otp/:phonenumber',
            name: 'otp',
            builder: (context, state) {
              return OtpScreen(
                phoneNumber: state.pathParameters['phonenumber']!,
              );
            },
          ),
        ]),
    GoRoute(
      path: '/meetingedit/:id',
      name: 'meetingedit',
      builder: (context, state) {
        return ChangeNotifierProvider(
          child: MeetingEditScreen(
            id: int.parse(state.pathParameters['id']!),
          ),
          create: (context) => MeetingEditState(),
        );
      },
    ),
    GoRoute(
      path: '/meetingadd',
      name: 'meetingadd',
      builder: (context, state) {
        return ChangeNotifierProvider(
          child: MeetingAddScreen(),
          create: (context) => MeetinAddState(),
        );
      },
    ),
    GoRoute(
      path: '/meetinsammary',
      name: 'meetinsammary',
      builder: (context, state) {
        Datum meetingData = state.extra as Datum;
        return ChangeNotifierProvider(
          create: (context) => MeetingSummaryState(),
          child: MeetingSummaryScreen(
            meetingItem: meetingData,
          ),
        );
      },
    ),
    GoRoute(
      path: '/privatemeetingadd',
      name: 'privatemeetingadd',
      builder: (context, state) {
        return ChangeNotifierProvider(
          child: PrivateMeetingAddScreen(),
          create: (context) => PrivateMeetingAddState(),
        );
      },
    ),
    GoRoute(
      path: '/privatemeetingedit/:id',
      name: 'privatemeetingedit',
      builder: (context, state) {
        return ChangeNotifierProvider(
          child: EditPrivateMeetingScreen(
            id: int.parse(state.pathParameters['id']!),
          ),
          create: (context) => EditPrivateMeetingState(),
        );
      },
    ),
    GoRoute(
      path: '/privatemeetinsammary',
      name: 'privatemeetinsammary',
      builder: (context, state) {
        DatumInPrivateMeeting meetingData =
            state.extra as DatumInPrivateMeeting;
        return ChangeNotifierProvider(
          create: (context) => PrivateMeetingSummaryState(),
          child: PrivateMeetingSummaryScreen(
            itemInPrivateMeeting: meetingData,
          ),
        );
      },
    ),
    GoRoute(
      path: '/report',
      name: 'report',
      builder: (context, state) {
        return ChangeNotifierProvider(
          create: (context) => ReportState(),
          child: ReportScreen(),
        );
      },
    ),
  ],
);
