import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../../../application/printer/printer_bloc.dart';
import '../../../../../common/theme/theme.dart';
import '../../../../../injection.dart';
import 'sections/setting_printer_section.dart';
import 'sections/setting_sync_section.dart';
import 'widgets/setting_left_panel.dart';

@RoutePage()
class SettingPage extends StatelessWidget implements AutoRouteWrapper {
  const SettingPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColor.white,
      body: BlocBuilder<PrinterBloc, PrinterState>(
        builder: (context, state) {
          return Row(
            children: [
              Expanded(flex: 2, child: SettingLeftPanel(state: state)),
              Expanded(
                flex: 4,
                child: switch (state.index) {
                  0 => const SettingPrinterSection(),
                  1 => const SettingSyncSection(),
                  _ => Container(),
                },
              ),
            ],
          );
        },
      ),
    );
  }

  @override
  Widget wrappedRoute(BuildContext context) =>
      BlocProvider(create: (context) => getIt<PrinterBloc>(), child: this);
}
