import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gap/gap.dart';
import 'package:krow/core/data/enums/state_status.dart';
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
import 'package:krow/core/presentation/styles/theme.dart';
import 'package:krow/core/presentation/widgets/ui_kit/kw_app_bar.dart';
import 'package:krow/features/profile/wages_forms/domain/bloc/wages_form_bloc.dart';
import 'package:krow/features/profile/wages_forms/presentation/components/routing_wage_form_visitor.dart';

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

  final _routingVisitor = const RoutingWageFormVisitor();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: KwAppBar(titleText: 'Wages Form', showNotification: true),
      body: BlocBuilder<WagesFormBloc, WagesFormState>(
        buildWhen: (previous, current) =>
            previous.actualForms != current.actualForms,
        builder: (context, state) {
          return ListView(
            primary: false,
            padding: const EdgeInsets.all(16),
            children: [
              Text(
                'View and manage your wage forms below. '
                'Select a form to review or update details.',
                style: AppTextStyles.bodySmallReg.copyWith(
                  color: AppColors.blackGray,
                ),
              ),
              const Gap(24),
              if (state.status == StateStatus.loading &&
                  state.actualForms.isEmpty)
                const Align(
                  alignment: AlignmentDirectional.bottomCenter,
                  child: CircularProgressIndicator(),
                ),
              for (final entry in state.actualForms)
                entry.visit(_routingVisitor),
              const Gap(90),
            ],
          );
        },
      ),
    );
  }
}
