import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:xiao_pet_tracker/xiao_connector/cubit/xiao_connector_cubit.dart';
import 'package:xiao_pet_tracker/xiao_connector/view/capture_view.dart';
import 'package:xiao_pet_tracker/xiao_connector/view/connected_view.dart';
import 'package:xiao_pet_tracker/xiao_connector/view/failure_view.dart';
import 'package:xiao_pet_tracker/xiao_connector/view/initial_view.dart';
import 'package:xiao_pet_tracker/xiao_connector/view/loading_view.dart';

@RoutePage()
class XiaoConnectorPage extends StatelessWidget {
  const XiaoConnectorPage({super.key});

  @override
  Widget build(BuildContext context) {
    return const XiaoConnectorView();
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: BlocBuilder<XiaoConnectorCubit, XiaoConnectorState>(
        builder: (context, state) {
          return switch (state.status) {
            XiaoConnectorStatus.initial => const InitialView(),
            XiaoConnectorStatus.loading => const LoadingView(),
            XiaoConnectorStatus.connected => const ConnectedView(),
            XiaoConnectorStatus.capturing => const CaptureView(),
            XiaoConnectorStatus.failure => const FailureView(),
          };
        },
      ),
    );
  }
}
