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

import '../app/theme.dart';

Future<void> showPremiumRequiredDialog(
  BuildContext context, {
  required String message,
  String? billingUrl,
}) async {
  await showDialog<void>(
    context: context,
    builder: (ctx) => AlertDialog(
      backgroundColor: AppTheme.surface,
      title: const Text('Premium richiesto'),
      content: Text(message),
      actions: [
        TextButton(
          onPressed: () => Navigator.pop(ctx),
          child: const Text('Chiudi'),
        ),
        if (billingUrl != null && billingUrl.isNotEmpty)
          FilledButton(
            onPressed: () async {
              final uri = Uri.parse(billingUrl);
              if (await canLaunchUrl(uri)) {
                await launchUrl(uri, mode: LaunchMode.externalApplication);
              }
              if (ctx.mounted) Navigator.pop(ctx);
            },
            style: FilledButton.styleFrom(backgroundColor: AppTheme.primaryRed),
            child: const Text('Attiva sul sito'),
          ),
      ],
    ),
  );
}
