import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_event.dart';
import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_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 AlarmManagementPage extends StatelessWidget {
  final String sosId;
  const AlarmManagementPage({super.key, required this.sosId});

  @override
  Widget build(BuildContext context) {
    return DefaultScaffold(
        title: 'Alarm Settings',
        child: BlocProvider(
          create: (context) => SosBloc(sosId: ''),
          child: BlocBuilder<SosBloc, SosState>(
            builder: (context, state) {
              final _bloc = BlocProvider.of<SosBloc>(context);

              return state is LoadingNewSate
                  ? const Center(
                      child: DefaultContainer(
                          width: 50,
                          height: 50,
                          child: CircularProgressIndicator()),
                    )
                  : Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        const SizedBox(
                          height: 10,
                        ),
                        const BodyMedium(
                          text: 'The Alarm Management',
                          fontWeight: FontWeight.w700,
                          fontSize: 12,
                          fontColor: ColorsManager.grayColor,
                        ),
                        const SizedBox(
                          height: 5,
                        ),
                        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: 'SOS Alarm',
                                      fontWeight: FontWeight.w400,
                                      fontSize: 15,
                                    ),
                                    trailing: Transform.scale(
                                        scale: .8,
                                        child: CupertinoSwitch(
                                          value: _bloc.enableAlarm,
                                          onChanged: (value) {
                                            context.read<SosBloc>().add(
                                                ToggleEnableAlarmEvent(value));
                                          },
                                          applyTheme: true,
                                        )),
                                  ),
                                ),
                                const Divider(
                                  color: ColorsManager.graysColor,
                                ),
                                SizedBox(
                                  height: 50,
                                  child: ListTile(
                                    contentPadding: EdgeInsets.zero,
                                    leading: const BodyLarge(
                                      text: 'Low Battery Reminder',
                                      fontWeight: FontWeight.w400,
                                      fontSize: 15,
                                    ),
                                    trailing: Transform.scale(
                                        scale: .8,
                                        child: CupertinoSwitch(
                                          value: _bloc.closingReminder,
                                          onChanged: (value) {
                                            context.read<SosBloc>().add(
                                                ToggleClosingReminderEvent(
                                                    value));
                                          },
                                          applyTheme: true,
                                        )),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),
                      ],
                    );
            },
          ),
        ));
  }
}
