import 'package:flutter/material.dart';
import 'package:flutter_gutter/flutter_gutter.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:moneymgr_mobile/routes/login/base_auth_page.dart';
import 'package:moneymgr_mobile/services/router/routes_list.dart';

class LoginScreen extends HookConsumerWidget {
  const LoginScreen({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    return BaseAuthPage(
      children: [
        Gutter(scaleFactor: 3),
        Text(
          "This application requires a token from MoneyMgr to be used.\n\nPlease create a token  on your Money Manager instance and make sure to click on \"For mobile app\" button. You can then enter here generated credentials.",
          textAlign: TextAlign.justify,
        ),
        Expanded(child: Container()),
        _LoginChoice(
          route: manualAuthPage,
          icon: Icons.edit_document,
          label: "Enter manually authentication information",
        ),
        _LoginChoice(
          route: qrAuthPath,
          icon: Icons.qr_code_2,
          label: "Scan authentication Qr Code",
        ),
        Gutter(scaleFactor: 3),
      ],
    );
  }
}

class _LoginChoice extends StatelessWidget {
  const _LoginChoice({
    required this.route,
    required this.label,
    required this.icon,
  });

  final String route;
  final String label;
  final IconData icon;

  @override
  Widget build(BuildContext context) {
    return FilledButton(
      onPressed: () => context.push(route),
      style: ButtonStyle(
        padding: WidgetStatePropertyAll(
          EdgeInsetsGeometry.symmetric(vertical: 20.0, horizontal: 30.0),
        ),
      ),
      child: Row(
        children: [
          Icon(icon, size: 25.0),
          Gutter(),
          Flexible(child: Text(label)),
        ],
      ),
    );
  }
}
