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/devices/bloc/four_scene_bloc/four_scene_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/four_scene_bloc/four_scene_event.dart';
import 'package:syncrow_app/features/devices/bloc/four_scene_bloc/four_scene_state.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/menu/view/widgets/manage_home/home_settings.dart';
import 'package:syncrow_app/features/shared_widgets/default_button.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/helpers/custom_page_route.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';

class ShareDevicePage extends StatelessWidget {
  final DeviceModel? device;
  const ShareDevicePage({super.key, this.device});
  @override
  Widget build(BuildContext context) {
    var spaces = HomeCubit.getInstance().spaces;
    return DefaultScaffold(
      title: 'Share Device',
      child: BlocProvider(
        create: (context) => FourSceneBloc(fourSceneId: device?.uuid ?? '')
          ..add(const FourSceneInitial()),
        child: BlocBuilder<FourSceneBloc, FourSceneState>(
          builder: (context, state) {
            final sensor = BlocProvider.of<FourSceneBloc>(context);
            return state is LoadingNewSate
                ? const Center(
                    child: DefaultContainer(
                        width: 50,
                        height: 50,
                        child: CircularProgressIndicator()),
                  )
                : RefreshIndicator(
                    onRefresh: () async {
                      sensor.add(const FourSceneInitial());
                    },
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        SizedBox(
                          height: MediaQuery.of(context).size.height * 0.05,
                        ),
                        const BodyLarge(
                          text: 'Sharing Method Not Supported',
                          fontSize: 15,
                          fontWeight: FontWeight.w400,
                          fontColor: ColorsManager.blackColor,
                        ),
                        const BodyMedium(
                          text:
                              'Currently, you cannot use the specified method to share Bluetooth mesh devices Zigbee devices, infrared devices, Bluetooth Beacon Devices, and certain Bluetooth LE devices with other users.',
                          fontSize: 14,
                          fontWeight: FontWeight.w400,
                          fontColor: ColorsManager.secondaryTextColor,
                        ),
                        const SizedBox(
                          height: 10,
                        ),
                        const BodyLarge(
                          text: 'Recommended Sharing Method',
                          fontSize: 15,
                          fontWeight: FontWeight.w400,
                          fontColor: ColorsManager.blackColor,
                        ),
                        const BodyMedium(
                          text:
                              'If the recipient is a home member or a reliable user, tap Me > Home Management > Add Member and add the recipient to your home. Then, devices in the home can be shared with the recipient in bulk.',
                          fontSize: 14,
                          fontWeight: FontWeight.w400,
                          fontColor: ColorsManager.secondaryTextColor,
                        ),
                        SizedBox(
                          height: MediaQuery.of(context).size.height * 0.15,
                        ),
                        Center(
                          child: SizedBox(
                            width: 250,
                            child: DefaultButton(
                                backgroundColor: ColorsManager.blueColor1,
                                borderRadius: 50,
                                onPressed: () {
                                  Navigator.of(context).push(CustomPageRoute(
                                      builder: (context) => HomeSettingsView(
                                            space: spaces!.first,
                                          )));
                                },
                                child: const Text('Add Home Member')),
                          ),
                        )
                      ],
                    ));
          },
        ),
      ),
    );
  }
}
