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

import '../../models/am_registration_data.dart';
import '../../widgets/personal_info_form_screen.dart';
import '../../services/reprise_session.dart';
import '../../models/card_assets.dart';

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

  @override
  Widget build(BuildContext context) {
    final registrationData = Provider.of<AmRegistrationData>(context, listen: false);
    
    final initialData = PersonalInfoData(
      firstName: registrationData.firstName,
      lastName: registrationData.lastName,
      phone: registrationData.phone,
      email: registrationData.email,
      address: registrationData.streetAddress,
      postalCode: registrationData.postalCode,
      city: registrationData.city,
    );

    return PersonalInfoFormScreen(
      stepText: 'Étape 1/4',
      title: 'Vos informations personnelles',
      cardColor: CardColorHorizontal.blue,
      initialData: initialData,
      minPersonNameLength: 2,
      previousRoute: RepriseSession.isActive ? '/login' : '/register-choice',
      onSubmit: (data, {hasSecondPerson, sameAddress}) {
        registrationData.updateIdentityInfo(
          firstName: data.firstName,
          lastName: data.lastName,
          phone: data.phone,
          email: data.email,
          streetAddress: data.address,
          postalCode: data.postalCode,
          city: data.city,
          password: '',
        );
        context.go('/am-register-step2');
      },
    );
  }
}
