import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/door_sensor_bloc/door_sensor_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/door_sensor_bloc/door_sensor_event.dart';
import 'package:syncrow_app/features/devices/bloc/door_sensor_bloc/door_sensor_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/utils/resource_manager/color_manager.dart';

class NotificationSettingsPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return DefaultScaffold(
        title: 'Notification Settings',
        child: BlocProvider(
          create: (context) => DoorSensorBloc(DSId: '')..add(const DoorSensorInitial()),
          child: BlocBuilder<DoorSensorBloc, DoorSensorState>(
            builder: (context, state) {
              final doorSensorBloc = BlocProvider.of<DoorSensorBloc>(context);

              return state is DoorSensorLoadingState
                  ? const Center(
                      child: DefaultContainer(
                          width: 50, height: 50, child: CircularProgressIndicator()),
                    )
                  : Column(
                      children: [
                        DefaultContainer(
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.start,
                            mainAxisSize: MainAxisSize.min,
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              SizedBox(
                                height: 50,
                                child: ListTile(
                                  contentPadding: EdgeInsets.zero,
                                  leading: const BodyLarge(
                                    text: 'Low Battery',
                                    fontWeight: FontWeight.normal,
                                  ),
                                  trailing: Transform.scale(
                                      scale: .8,
                                      child: CupertinoSwitch(
                                        value: doorSensorBloc.lowBattery,
                                        onChanged: (value) {
                                          context
                                              .read<DoorSensorBloc>()
                                              .add(ToggleLowBatteryEvent(value));
                                        },
                                        applyTheme: true,
                                      )),
                                ),
                              ),
                              const Divider(
                                color: ColorsManager.graysColor,
                              ),
                              SizedBox(
                                height: 50,
                                child: ListTile(
                                  contentPadding: EdgeInsets.zero,
                                  leading: const BodyLarge(
                                    text: 'Closing Reminder',
                                    fontWeight: FontWeight.normal,
                                  ),
                                  trailing: Transform.scale(
                                      scale: .8,
                                      child: CupertinoSwitch(
                                        value: doorSensorBloc.closingReminder,
                                        onChanged: (value) {
                                          context
                                              .read<DoorSensorBloc>()
                                              .add(ToggleClosingReminderEvent(value));
                                        },
                                        applyTheme: true,
                                      )),
                                ),
                              ),
                              const Divider(
                                color: ColorsManager.graysColor,
                              ),
                              SizedBox(
                                height: 50,
                                child: ListTile(
                                  contentPadding: EdgeInsets.zero,
                                  leading: const BodyLarge(
                                    text: 'Door Alarm',
                                    fontWeight: FontWeight.normal,
                                  ),
                                  trailing: Transform.scale(
                                      scale: .8,
                                      child: CupertinoSwitch(
                                        value: doorSensorBloc.closingReminder,
                                        onChanged: (value) {
                                          context
                                              .read<DoorSensorBloc>()
                                              .add(ToggleDoorAlarmEvent(value));
                                        },
                                        applyTheme: true,
                                      )),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    );
            },
          ),
        ));
  }
}
