import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/water_leak_bloc/water_leak_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/water_leak_bloc/water_leak_event.dart';
import 'package:syncrow_app/features/devices/bloc/water_leak_bloc/water_leak_state.dart';

import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';

class NotificationSettingsPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return DefaultScaffold(
        title: 'Notification Settings',
        child: BlocProvider(
          create: (context) =>
              WaterLeakBloc(WLId: '')..add(const WaterLeakInitial()),
          child: BlocBuilder<WaterLeakBloc, WaterLeakState>(
            builder: (context, state) {
              final waterLeakBloc = BlocProvider.of<WaterLeakBloc>(context);

              return state is WaterLeakLoading
                  ? const Center(
                      child: DefaultContainer(
                          width: 50,
                          height: 50,
                          child: CircularProgressIndicator()),
                    )
                  : Column(
                      children: [
                        DefaultContainer(
                          child: Padding(
                            padding: const EdgeInsets.only(left: 10, right: 10),
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.start,
                              mainAxisSize: MainAxisSize.min,
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                SizedBox(
                                  height: 50,
                                  child: ListTile(
                                    contentPadding: EdgeInsets.zero,
                                    leading: const BodyMedium(
                                      text: 'Low Battery Alarm',
                                      fontWeight: FontWeight.w400,
                                      fontSize: 15,
                                    ),
                                    trailing: Transform.scale(
                                        scale: .8,
                                        child: CupertinoSwitch(
                                          value: waterLeakBloc.lowBattery,
                                          onChanged: (value) {
                                            context.read<WaterLeakBloc>().add(
                                                ToggleLowBatteryEvent(value));
                                          },
                                          applyTheme: true,
                                        )),
                                  ),
                                ),
                                const Divider(
                                  color: ColorsManager.graysColor,
                                ),
                                SizedBox(
                                  height: 50,
                                  child: ListTile(
                                    contentPadding: EdgeInsets.zero,
                                    leading: const BodyLarge(
                                      text: 'Water Leakage Alarm',
                                      fontWeight: FontWeight.w400,
                                      fontSize: 15,
                                    ),
                                    trailing: Transform.scale(
                                        scale: .8,
                                        child: CupertinoSwitch(
                                          value: waterLeakBloc.closingReminder,
                                          onChanged: (value) {
                                            context.read<WaterLeakBloc>().add(
                                                ToggleClosingReminderEvent(
                                                    value));
                                          },
                                          applyTheme: true,
                                        )),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),
                      ],
                    );
            },
          ),
        ));
  }
}
