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

import '../../models/am_registration_data.dart';
import '../../utils/data_generator.dart';
import '../../widgets/personal_info_form_screen.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);
    
    // Générer des données de test si vide
    PersonalInfoData initialData;
    if (registrationData.firstName.isEmpty) {
      final genFirstName = DataGenerator.firstName();
      final genLastName = DataGenerator.lastName();
      initialData = PersonalInfoData(
        firstName: genFirstName,
        lastName: genLastName,
        phone: DataGenerator.phone(),
        email: DataGenerator.email(genFirstName, genLastName),
        address: DataGenerator.address(),
        postalCode: DataGenerator.postalCode(),
        city: DataGenerator.city(),
      );
    } else {
      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,
      previousRoute: '/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');
      },
    );
  }
}
