import 'package:flutter/cupertino.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/home/bloc/home_bloc.dart';
import 'package:syncrow_web/pages/home/bloc/home_event.dart';
import 'package:syncrow_web/pages/home/view/home_page_mobile.dart';
import 'package:syncrow_web/pages/home/view/home_page_web.dart';
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with HelperResponsiveLayout {
  @override
  void initState() {
    _fetchUserInfo();

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    if (isSmallScreenSize(context) || isMediumScreenSize(context)) {
      return HomeMobilePage();
    }

    return const HomeWebPage();
  }

  void _fetchUserInfo() {
    final bloc = context.read<HomeBloc>();
    if (bloc.user == null) bloc.add(const FetchUserInfo());
  }
}
