import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:go_router/go_router.dart';

import '../../models/am_registration_data.dart';
import '../../models/card_assets.dart';
import '../../widgets/professional_info_form_screen.dart';

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

  @override
  Widget build(BuildContext context) {
    return Consumer<AmRegistrationData>(
      builder: (context, registrationData, _) {
        final initialData = ProfessionalInfoData(
          photoPath: registrationData.photoPath,
          photoBytes: registrationData.photoBytes,
          photoFilename: registrationData.photoFilename,
          photoConsent: registrationData.photoConsent,
          dateOfBirth: registrationData.dateOfBirth,
          birthCity: registrationData.birthCity,
          birthCountry: registrationData.birthCountry,
          nir: registrationData.nir,
          agrementNumber: registrationData.agrementNumber,
          agreementDate: registrationData.agreementDate,
          capacity: registrationData.capacity,
          placesAvailable: registrationData.placesAvailable,
        );

        return ProfessionalInfoFormScreen(
          key: ValueKey(
            'am-pro-${registrationData.dateOfBirth?.millisecondsSinceEpoch}'
            '-${registrationData.agreementDate?.millisecondsSinceEpoch}'
            '-${registrationData.placesAvailable}'
            '-${registrationData.nir}',
          ),
          stepText: 'Étape 2/4',
          title: 'Vos informations professionnelles',
          cardColor: CardColorHorizontal.green,
          initialData: initialData,
          previousRoute: '/am-register-step1',
          onSubmit: (data) {
            registrationData.updateProfessionalInfo(
              photoPath: data.photoPath,
              photoBytes: data.photoBytes,
              photoFilename: data.photoFilename,
              photoConsent: data.photoConsent,
              dateOfBirth: data.dateOfBirth,
              birthCity: data.birthCity,
              birthCountry: data.birthCountry,
              nir: data.nir,
              agrementNumber: data.agrementNumber,
              agreementDate: data.agreementDate,
              capacity: data.capacity,
              placesAvailable: data.placesAvailable,
            );
            context.go('/am-register-step3');
          },
        );
      },
    );
  }
}
