import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
import 'package:syncrow_app/features/scene/widgets/select_smart_scene/smart_enable_autoamtion.dart';
import 'package:syncrow_app/features/scene/widgets/select_smart_scene/smart_enable_tab_run.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/generated/assets.dart';
import 'package:syncrow_app/navigation/navigate_to_route.dart';
import 'package:syncrow_app/navigation/routing_constants.dart';
import 'package:syncrow_app/utils/context_extension.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';

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

  @override
  Widget build(BuildContext context) {
    final sceneType = context.read<CreateSceneBloc>().sceneType;
    final sceneId = ModalRoute.of(context)!.settings.arguments as String;
    return DefaultScaffold(
      title: "Select Smart Scene",
      padding: const EdgeInsets.only(top: 24),
      leading: IconButton(
          onPressed: () {
            navigateToRoute(context, Routes.sceneTasksRoute);
          },
          icon: const Icon(
            Icons.arrow_back_ios,
          )),
      // height: sceneType.name == CreateSceneEnum.deviceStatusChanges.name
      //     ? 260
      //     : 200,
      height: MediaQuery.sizeOf(context).height,
      child: Column(
        children: [
          DefaultContainer(
            width: double.infinity,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Visibility(
                  visible: sceneType.name ==
                      CreateSceneEnum.deviceStatusChanges.name,
                  child: SceneListTile(
                    assetPath: Assets.handClickIcon,
                    titleString: "Tap To Run",
                    subtitleString: '',
                    trailingWidget: const Icon(
                      Icons.arrow_forward_ios_rounded,
                      color: ColorsManager.greyColor,
                    ),
                    onPressed: () {
                      context.customBottomSheet(
                        child: const SmartEnableTabRun(),
                      );
                    },
                  ),
                ),
                Visibility(
                  visible: sceneType.name ==
                      CreateSceneEnum.deviceStatusChanges.name,
                  child: const Divider(
                    color: ColorsManager.dividerColor,
                  ),
                ),
                SceneListTile(
                  assetPath: Assets.refreshIcon,
                  titleString: "Automation",
                  subtitleString: '',
                  trailingWidget: const Icon(
                    Icons.arrow_forward_ios_rounded,
                    color: ColorsManager.greyColor,
                  ),
                  onPressed: () {
                    context.customBottomSheet(
                      child: SmartEnableAutomation(automationId: sceneId),
                    );
                  },
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
