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/scene/bloc/scene_bloc/scene_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
import 'package:syncrow_app/features/scene/widgets/select_smart_scene/smart_tab_run_list.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/utils/context_extension.dart';

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

  @override
  Widget build(BuildContext context) {
    return DefaultContainer(
      height: context.height * 0.5,
      width: double.infinity,
      child: BlocBuilder<SceneBloc, SceneState>(
        bloc: context.read<SceneBloc>()
          ..add(LoadScenes(HomeCubit.getInstance().selectedSpace?.id ?? '',HomeCubit.getInstance().selectedSpace!)),
        builder: (context, state) {
          if (state is SceneLoading) {
            return const Align(
                alignment: Alignment.topCenter,
                child: LinearProgressIndicator());
          }
          if (state is SceneLoaded) {
            return SmartSceneSelectTabToRunList(scenes: state.scenes);
          }
          return const SizedBox.shrink();
        },
      ),
    );
  }
}

