import 'package:flutter/material.dart';
import 'package:navigation/navigation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
// import 'package:sf_app_platform/payments/view/screens/core/dashboard_screen.dart';
// import 'package:sf_app_platform/payments/view/screens/login_screen.dart';

class PhoneCodeScreen extends ConsumerWidget {
  // final String phone;
  final NavigationContract navigationContract;

  PhoneCodeScreen({super.key, required this.navigationContract});
  // const PhoneCodeScreen({super.key, required this.phone});

  // class PhoneCodeScreenState extends State<PhoneCodeScreen> {
  final focusNodes = List<FocusNode>.generate(6, (int i) {
    return FocusNode();
  });

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    return Scaffold(
      body: Container(
        margin: EdgeInsets.all(30),
        child: Expanded(
          child: Center(
            child: Column(
              spacing: 15,
              children: [
                Spacer(flex: 8),
                Text(
                  "Conéctate",
                  style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30),
                ),
                Text.rich(
                  TextSpan(
                    text: "Hemos enviado el código al ",
                    children: [
                      TextSpan(
                        // text: widget.phone,
                        style: TextStyle(fontWeight: FontWeight.bold),
                      ),
                    ],
                  ),
                ),
                Text("Introduce el código aquí"),
                Row(
                  spacing: 20,
                  children: List<Widget>.generate(6, (int i) {
                    return Expanded(
                      child: TextField(
                        focusNode: focusNodes[i],
                        keyboardType: TextInputType.number,
                        decoration: InputDecoration(
                          hintText: "0",
                          counterText: "",
                          border: OutlineInputBorder(),
                        ),
                        maxLength: 1,
                        onChanged: (String value) => {
                          value != ""
                              ? focusNodes[i + 1].requestFocus()
                              : focusNodes[i - 1].requestFocus(),
                        },
                      ),
                    );
                  }),
                ),
                FilledButton(
                  onPressed: () => {navigationContract.pushTo(AppRoutes.login)},
                  child: Text("Entrar"),
                ),
                Text("¿No lo has recibido?"),
                TextButton(
                  onPressed: () => {},
                  child: Text(
                    "Volver a intentarlo",
                    style: TextStyle(fontWeight: FontWeight.bold),
                  ),
                ),
                Spacer(flex: 10),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
