import 'package:coda_project/presentation/screens/notifications_screen.dart';
import 'package:coda_project/presentation/screens/user_settings_screen.dart';
import 'package:flutter/material.dart';
import '../widgets/finance_summary_card.dart';
import '../widgets/work_day_card.dart';
import '../widgets/settings_bar.dart';

class FinanceScreen extends StatefulWidget {
  final void Function(bool isScrollingDown)? onScrollEvent;

  const FinanceScreen({super.key, this.onScrollEvent});

  @override
  State<FinanceScreen> createState() => _FinanceScreenState();
}

class _FinanceScreenState extends State<FinanceScreen> {
  String dropdownValue = "الكل";
  late ScrollController scrollController;

  @override
  void initState() {
    super.initState();
    scrollController = ScrollController();
  }

  @override
  void dispose() {
    scrollController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Directionality(
      textDirection: TextDirection.ltr,
      child: SafeArea(
        child: CustomScrollView(
          
          controller: scrollController,
          physics: const BouncingScrollPhysics(),
          slivers: [
              SliverToBoxAdapter(
                child:  SettingsBar(
                    selectedIndex: 0,
                    showBackButton: false,
                    iconPaths: [
                      'assets/images/user.svg',
                      'assets/images/ball.svg',
                    ],
                    onTap: (index) {
                      if (index == 0) {
                        Navigator.push(
                          context,
                          MaterialPageRoute(
                            builder: (context) => UserSettingsScreen(),
                          ),
                        );
                      } else if (index == 1) {
                        Navigator.push(
                          context,
                          MaterialPageRoute(
                            builder: (context) => NotificationsScreen(),
                          ),
                        );
                      }
                    },
                  ),
              ),
              const SliverToBoxAdapter(child: SizedBox(height: 5)),
              
              /// SUMMARY CARD
              SliverToBoxAdapter(
                child: FinanceSummaryCard(
                  totalAmount: "333,000",
                  dropdownValue: dropdownValue,
                  onCalendarTap: () => showDatePicker(
                    context: context,
                    initialDate: DateTime.now(),
                    firstDate: DateTime(2020),
                    lastDate: DateTime(2030),
                  ),
                  onDropdownChanged: (value) {
                    setState(() => dropdownValue = value!);
                  },
                ),
              ),
          
              /// WORK DAY CARDS
              SliverList(
                delegate: SliverChildBuilderDelegate(
                  (context, index) {
                    return const WorkDayCard();
                  },
                  childCount: 3,
                ),
              ),
          
              const SliverToBoxAdapter(child: SizedBox(height: 120)),
          ],
        ),
      ),
    );
  }
}
