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/model/scene_settings_route_arguments.dart';
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.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/resource_manager/strings_manager.dart';

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

  @override
  Widget build(BuildContext context) {
    return DefaultScaffold(
      title: StringsManager.createScene,
      padding: const EdgeInsets.only(top: 24),
      leading: IconButton(
          onPressed: () {
            navigateToRoute(context, Routes.sceneTasksRoute);
          },
          icon: const Icon(
            Icons.arrow_back_ios,
          )),
      child: Column(
        children: [
          DefaultContainer(
            width: double.infinity,
            margin: const EdgeInsets.symmetric(vertical: 4),
            child: const SceneListTile(
              assetPath: Assets.handClickIcon,
              titleString: StringsManager.tapToRun,
              subtitleString: StringsManager.turnOffAllLights,
            ),
            onTap: () {
              Navigator.pushNamed(
                context,
                Routes.sceneTasksRoute,
                arguments: SceneSettingsRouteArguments(
                  sceneType: CreateSceneEnum.tabToRun.name,
                  sceneId: '',
                  sceneName: '',
                ),
              );
              context.read<CreateSceneBloc>().add(const ClearTaskListEvent());
              context
                  .read<CreateSceneBloc>()
                  .add(const SceneTypeEvent(CreateSceneEnum.tabToRun));
            },
          ),
          DefaultContainer(
            width: double.infinity,
            margin: const EdgeInsets.symmetric(vertical: 4),
            child: const SceneListTile(
              assetPath: Assets.refreshIcon,
              titleString: StringsManager.whenDeviceStatusChanges,
              subtitleString: StringsManager.whenUnusualActivityIsDetected,
            ),
            onTap: () {
              Navigator.pushNamed(
                context,
                Routes.sceneControlDevicesRoute,
                arguments: SceneSettingsRouteArguments(
                  sceneType: CreateSceneEnum.deviceStatusChanges.name,
                  sceneId: '',
                  sceneName: '',
                ),
              );
              context
                  .read<CreateSceneBloc>()
                  .add(const ClearTaskListEvent(isAutomation: true));
              context.read<CreateSceneBloc>().add(
                  const SceneTypeEvent(CreateSceneEnum.deviceStatusChanges));
            },
          ),
        ],
      ),
    );
  }
}
