import 'package:auto_route/annotations.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gap/gap.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/preview_wage_from_visitor.dart';
import 'package:krow/features/profile/wages_forms/presentation/components/title_wage_form_visitor.dart';

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

  @override
  Widget build(BuildContext context) {
    final form = context.read<WagesFormBloc>().state.activeForm;
    const titleVisitor = TitleWageFormVisitor(isPreview: true);
    final previewData =
        form != null ? form.visit(const PreviewWageFormVisitor()) : {};

    return Scaffold(
      appBar: KwAppBar(
        titleText: form != null ? form.visit(titleVisitor) : 'Preview',
        showNotification: true,
      ),
      body: Container(
        margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 24),
        decoration: const BoxDecoration(
          color: AppColors.grayPrimaryFrame,
          borderRadius: BorderRadius.all(Radius.circular(12)),
        ),
        child: SingleChildScrollView(
          primary: false,
          padding: const EdgeInsets.all(16),
          child: Column(
            spacing: 16,
            children: [
              for (final entry in previewData.entries)
                Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      '${entry.key}:',
                      textAlign: TextAlign.start,
                      style: AppTextStyles.bodyMediumMed.copyWith(
                        color: AppColors.blackGray,
                      ),
                    ),
                    const Gap(12),
                    Expanded(
                      child: Text(
                        entry.value,
                        textAlign: TextAlign.end,
                        style: AppTextStyles.bodyMediumMed,
                        overflow: TextOverflow.ellipsis,
                      ),
                    ),
                  ],
                ),
            ],
          ),
        ),
      ),
    );
  }
}
