import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../../shared/widgets/app_scaffold.dart';
import 'route_observer.dart';
import '../../features/home/home_page.dart';
import '../../features/messages/message_list_page.dart';
import '../../features/profile/profile_page.dart';
import '../../features/expense/expense_apply_import_page.dart';
import '../../features/expense/expense_list_page.dart';
import '../../features/expense/expense_create_page.dart';
import '../../features/expense/expense_detail_page.dart';
import '../../features/overtime/overtime_list_page.dart';
import '../../features/overtime/overtime_create_page.dart';
import '../../features/overtime/overtime_detail_page.dart';
import '../../features/vehicle/vehicle_list_page.dart';
import '../../features/vehicle/vehicle_create_page.dart';
import '../../features/vehicle/vehicle_detail_page.dart';
import '../../features/outing_log/outing_log_list_page.dart';
import '../../features/outing_log/outing_log_create_page.dart';
import '../../features/outing_log/outing_log_detail_page.dart';
import '../../features/announcement/announcement_list_page.dart';
import '../../features/announcement/announcement_detail_page.dart';
import '../../features/announcement/announcement_create_page.dart';
import '../../features/expense_apply/expense_apply_list_page.dart';
import '../../features/expense_apply/expense_apply_detail_page.dart';
import '../../features/expense_apply/expense_apply_create_page.dart';
import '../../features/report/expense_detail_report_page.dart';
import '../../features/report/overtime_detail_report_page.dart';
import '../../features/report/vehicle_detail_report_page.dart';
import '../../features/report/expense_apply_detail_report_page.dart';
import '../../features/report/outing_log_detail_report_page.dart';
import '../../features/admin/admin_permissions_page.dart';

GoRouter createAppRouter() {
  return GoRouter(
    observers: [routeObserver],
    initialLocation: '/',
    routes: [
      GoRoute(path: '/', pageBuilder: (_, _) => const MaterialPage(child: AppScaffold(showTabBar: true, body: HomePage()))),
      GoRoute(path: '/messages', pageBuilder: (_, _) => const MaterialPage(child: AppScaffold(showTabBar: true, body: MessageListPage()))),
      GoRoute(path: '/profile', pageBuilder: (_, _) => const MaterialPage(child: AppScaffold(showTabBar: true, body: ProfilePage()))),
      GoRoute(path: '/expense/list', pageBuilder: (_, _) => const MaterialPage(child: AppScaffold(body: ExpenseListPage()))),
      GoRoute(path: '/expense/import-apply', pageBuilder: (_, _) => const MaterialPage(child: AppScaffold(body: ExpenseApplyImportPage(), resizeToAvoidBottomInset: false))),
      GoRoute(path: '/expense/create', pageBuilder: (_, state) => MaterialPage(child: AppScaffold(body: ExpenseCreatePage(editId: state.uri.queryParameters['id']), resizeToAvoidBottomInset: false))),
      GoRoute(path: '/expense/detail/:billNo', pageBuilder: (_, state) => MaterialPage(child: AppScaffold(body: ExpenseDetailPage(billNo: state.pathParameters['billNo']!, queryId: int.tryParse(state.uri.queryParameters['queryId'] ?? '0') ?? 0)))),
      GoRoute(path: '/overtime/list', pageBuilder: (_, _) => const MaterialPage(child: AppScaffold(body: OvertimeListPage()))),
      GoRoute(path: '/overtime/create', pageBuilder: (_, state) => MaterialPage(child: AppScaffold(body: OvertimeCreatePage(editId: state.uri.queryParameters['id'])))),
      GoRoute(path: '/overtime/detail/:id', pageBuilder: (_, state) => MaterialPage(child: AppScaffold(body: OvertimeDetailPage(id: state.pathParameters['id']!)))),
      GoRoute(path: '/vehicle/list', pageBuilder: (_, _) => const MaterialPage(child: AppScaffold(body: VehicleListPage()))),
      GoRoute(path: '/vehicle/create', pageBuilder: (_, state) => MaterialPage(child: AppScaffold(body: VehicleCreatePage(editId: state.uri.queryParameters['id'])))),
      GoRoute(path: '/vehicle/detail/:id', pageBuilder: (_, state) => MaterialPage(child: AppScaffold(body: VehicleDetailPage(id: state.pathParameters['id']!)))),
      GoRoute(path: '/outing-log/list', pageBuilder: (_, _) => const MaterialPage(child: AppScaffold(body: OutingLogListPage()))),
      GoRoute(path: '/outing-log/create', pageBuilder: (_, _) => const MaterialPage(child: AppScaffold(body: OutingLogCreatePage()))),
      GoRoute(path: '/outing-log/detail/:id', pageBuilder: (_, state) => MaterialPage(child: AppScaffold(body: OutingLogDetailPage(id: state.pathParameters['id']!)))),
      GoRoute(path: '/announcement/list', pageBuilder: (_, _) => const MaterialPage(child: AppScaffold(body: AnnouncementListPage()))),
      GoRoute(path: '/announcement/detail/:id', pageBuilder: (_, state) => MaterialPage(child: AppScaffold(body: AnnouncementDetailPage(id: state.pathParameters['id']!)))),
      GoRoute(path: '/announcement/create', pageBuilder: (_, _) => const MaterialPage(child: AppScaffold(body: AnnouncementCreatePage()))),
      GoRoute(path: '/expense-apply/list', pageBuilder: (_, _) => const MaterialPage(child: AppScaffold(body: ExpenseApplyListPage()))),
      GoRoute(path: '/expense-apply/detail/:billNo', pageBuilder: (_, state) => MaterialPage(child: AppScaffold(body: ExpenseApplyDetailPage(billNo: state.pathParameters['billNo']!, queryId: int.tryParse(state.uri.queryParameters['queryId'] ?? '0') ?? 0)))),
      GoRoute(path: '/expense-apply/create', pageBuilder: (_, state) => MaterialPage(child: AppScaffold(body: ExpenseApplyCreatePage(id: state.uri.queryParameters['id']), resizeToAvoidBottomInset: false))),
      GoRoute(path: '/report/expense-detail', pageBuilder: (_, _) => const MaterialPage(child: AppScaffold(body: ExpenseDetailReportPage()))),
      GoRoute(path: '/report/expense-apply-detail', pageBuilder: (_, _) => const MaterialPage(child: AppScaffold(body: ExpenseApplyDetailReportPage()))),
      GoRoute(path: '/report/overtime-detail', pageBuilder: (_, _) => const MaterialPage(child: AppScaffold(body: OvertimeDetailReportPage()))),
      GoRoute(path: '/report/vehicle-detail', pageBuilder: (_, _) => const MaterialPage(child: AppScaffold(body: VehicleDetailReportPage()))),
      GoRoute(path: '/report/outing-log-detail', pageBuilder: (_, _) => const MaterialPage(child: AppScaffold(body: OutingLogDetailReportPage()))),
      GoRoute(path: '/admin/permissions', pageBuilder: (_, _) => const MaterialPage(child: AppScaffold(body: AdminPermissionsPage()))),
    ],
  );
}
