import 'package:country_code_picker/country_code_picker.dart';
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:sf_localizations/sf_localizations.dart';

class SignupPersonalScreen extends StatelessWidget {
  final TextEditingController firstNameTextFieldController;
  final TextEditingController lastNameTextFieldController;
  final TextEditingController documentNumberTextFieldController;
  final TextEditingController phoneTextFieldController;
  final TextEditingController emailTextFieldController;

  final String? documentTypeSelected;
  final ValueChanged<String?> onDocumentTypeChanged;

  final String firstNameLabel;
  final String firstNameHint;

  final String lastNameLabel;
  final String lastNameHint;

  final List<String> documentTypeOptions;
  final String documentTypeHint;

  final String documentNumberLabel;
  final String documentNumberHint;

  final String phoneLabel;
  final String phoneHint;
  final ValueChanged<CountryCode> onDialCodeChanged;

  final String emailLabel;
  final String emailHint;

  final bool acceptTerms;
  final ValueChanged<bool?>? onAcceptTermsPressed;
  final String termsText;
  final ThemePort theme;

  const SignupPersonalScreen({
    super.key,
    required this.firstNameTextFieldController,
    required this.lastNameTextFieldController,
    required this.documentNumberTextFieldController,
    required this.phoneTextFieldController,
    required this.emailTextFieldController,
    required this.documentTypeSelected,
    required this.onDocumentTypeChanged,
    required this.firstNameLabel,
    required this.firstNameHint,
    required this.lastNameLabel,
    required this.lastNameHint,
    required this.documentTypeOptions,
    required this.documentTypeHint,
    required this.documentNumberLabel,
    required this.documentNumberHint,
    required this.phoneLabel,
    required this.phoneHint,
    required this.onDialCodeChanged,
    required this.emailLabel,
    required this.emailHint,
    required this.acceptTerms,
    required this.onAcceptTermsPressed,
    required this.termsText,
    required this.theme,
  });

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Column(
        children: [
          CustomTextField(
            label: firstNameLabel,
            hint: firstNameHint,
            controller: firstNameTextFieldController,
          ),
          const SizedBox(height: 8),
          CustomTextField(
            label: lastNameLabel,
            hint: lastNameHint,
            controller: lastNameTextFieldController,
          ),
          const SizedBox(height: 8),
          Row(
            children: [
              Expanded(
                child: CustomDropdown(
                  items: documentTypeOptions
                      .map(Text.new)
                      .toList(growable: false),
                  values: documentTypeOptions,
                  value: documentTypeSelected,
                  hint: documentTypeHint,
                  onChanged: (v) => onDocumentTypeChanged(v as String?),
                ),
              ),
              const SizedBox(width: 8),
              Expanded(
                child: CustomTextField(
                  label: documentNumberLabel,
                  hint: documentNumberHint,
                  controller: documentNumberTextFieldController,
                ),
              ),
            ],
          ),
          const SizedBox(height: 8),
          Align(
            alignment: Alignment.bottomLeft,
            child: Text(phoneLabel, style: const TextStyle(fontSize: 14)),
          ),
          const SizedBox(height: 8),
          Row(
            spacing: 10,
            children: [
              CountryPrefixPicker(
                headerText: context.translate(I18n.selectYourCountry),
                onChanged: onDialCodeChanged,
              ),
              Expanded(
                child: CustomTextField(
                  controller: phoneTextFieldController,
                  hint: context.translate(I18n.phoneNumber),
                  keyboardType: TextInputType.number,
                ),
              ),
            ],
          ),
          const SizedBox(height: 8),
          CustomTextField(
            label: emailLabel,
            hint: emailHint,
            keyboardType: TextInputType.emailAddress,
            controller: emailTextFieldController,
          ),

          CheckboxListTile(
            value: acceptTerms,
            onChanged: onAcceptTermsPressed,
            title: Text(
              termsText,
              style: TextStyle(fontSize: 16, letterSpacing: 0),
            ),
            checkboxScaleFactor: 1.5,
            contentPadding: EdgeInsets.zero,
            activeColor: theme.getColorFor(ThemeCode.buttonPrimary),
            controlAffinity: ListTileControlAffinity.leading,
          ),
        ],
      ),
    );
  }
}
