import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
import 'package:syncrow_app/features/booking_system/data/booking_dummy_source.dart';
import 'package:syncrow_app/features/booking_system/presentation/blocs/upcoming_bookings_bloc/upcoming_bookings_bloc.dart';
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
import '../blocs/past_bookings_bloc/past_bookings_bloc.dart';
import '../widgets/booking_appbar_widget.dart';
import '../widgets/current_balance_widget.dart';
import '../widgets/past_booking_widget.dart';
import '../widgets/upcoming_bookings_widget.dart';

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

  @override
  Widget build(BuildContext context) {
    return MultiBlocProvider(
        providers: [
          BlocProvider<UpcomingBookingsBloc>(
            create: (_) => UpcomingBookingsBloc(BookingDummySource())
              ..add(GetUpcomingBookingsEvent()),
          ),
          BlocProvider<PastBookingsBloc>(
            create: (_) => PastBookingsBloc(BookingDummySource())
              ..add(GetPastBookingsEvent()),
          )
        ],
        child: DefaultScaffold(
          appBar: BookingAppBar(),
          child: Padding(
            padding: EdgeInsets.symmetric(horizontal: 10),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                SizedBox(
                  height: 20,
                ),
                Expanded(
                  flex: 2,
                  child: CurrentBalanceWidget(
                    userBalance: HomeCubit.user!.points == null
                        ? '0'
                        : HomeCubit.user!.points.toString(),
                  ),
                ),
                SizedBox(
                  height: 20,
                ),
                Expanded(
                  flex: 8,
                  child: Column(
                    children: [
                      UpcomingBookingsWidget(),
                      SizedBox(
                        height: 10,
                      ),
                      PastBookingsWidget(),
                    ],
                  ),
                )
              ],
            ),
          ),
        ));
  }
}
