import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:share_plus/share_plus.dart';

import 'api_client.dart';

Future<void> shareRegiaLink(
  BuildContext context,
  WidgetRef ref, {
  required String sessionId,
  required String shareSubject,
}) async {
  try {
    final link = await ref.read(apiClientProvider).createRegiaLink(sessionId);
    await Share.share(
      'Apri questo link per gestire il punteggio della diretta:\n${link.regiaUrl}',
      subject: shareSubject,
    );
  } catch (_) {
    if (context.mounted) {
      ScaffoldMessenger.of(context).showSnackBar(
        const SnackBar(content: Text('Errore generazione link regia')),
      );
    }
  }
}
