import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dialogs/flutter_dialogs.dart';
import 'package:prosappco/src/components/pop_appbar.dart';
import 'package:prosappco/src/services/local_notifications.dart';

class LocalNotificationScreen extends StatelessWidget {
  const LocalNotificationScreen({Key? key}) : super(key: key);

  void showCustomDialog(BuildContext context, String title, String content) {
    showPlatformDialog(
      context: context,
      builder: (_) => BasicDialogAlert(
        title: Text(title),
        content: Text(content),
        actions: <Widget>[
          BasicDialogAction(
            onPressed: () {
              Navigator.pop(context);
            },
            title: const Text('Cerrar'),
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    if (kIsWeb) {
      return Scaffold(
        appBar: PopAppbar(
          onPressed: () {
            Navigator.pop(context);
          },
          label: 'Notificaciones',
        ),
        body: Center(
          child: ElevatedButton(
            onPressed: () {
              showCustomDialog(
                context,
                'Nueva notificación!',
                'Esta es una notificación de Flutter',
              );
            },
            child: const Text('Lanzar notificación'),
          ),
        ),
      );
    } else {
      return Scaffold(
        appBar: PopAppbar(
          onPressed: () {
            Navigator.pop(context);
          },
          label: 'Notificaciones',
        ),
        body: Center(
          child: ElevatedButton(
            onPressed: () {
              showNotification(
                'Nueva notificación!',
                'Esta es una notificación de prosapp!',
              );
            },
            child: const Text('Lanzar notificación'),
          ),
        ),
      );
    }
  }
}
