import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../app/theme.dart';
import '../../core/config.dart';
import '../../shared/widgets/primary_cta.dart';

class NoTeamOnboarding extends StatelessWidget {
  const NoTeamOnboarding({required this.theme});

  final ThemeData theme;

  String get _signupUrl {
    final base = AppConfig.apiBaseUrl.replaceAll(RegExp(r'/api/v1/?$'), '');
    return '$base/signup';
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Padding(
        padding: const EdgeInsets.all(28),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Icon(Icons.groups_outlined, size: 64, color: AppTheme.textSecondary),
            const SizedBox(height: 16),
            Text(
              'Completa l\'iscrizione sul sito',
              style: theme.textTheme.titleLarge,
              textAlign: TextAlign.center,
            ),
            const SizedBox(height: 12),
            Text(
              'Crea la tua squadra e scegli il piano Free o Premium da browser. '
              'Poi torna qui con le stesse credenziali.',
              style: theme.textTheme.bodyMedium,
              textAlign: TextAlign.center,
            ),
            const SizedBox(height: 24),
            PrimaryCta(
              label: 'VAI AL SITO',
              icon: Icons.open_in_new,
              onPressed: () async {
                final uri = Uri.parse(_signupUrl);
                if (await canLaunchUrl(uri)) {
                  await launchUrl(uri, mode: LaunchMode.externalApplication);
                }
              },
            ),
          ],
        ),
      ),
    );
  }
}
