import 'package:flutter/material.dart';
import 'package:test_sa/controllers/notification/firebase_notification_manger.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/models/system_notification_model.dart';
import 'package:test_sa/views/widgets/loaders/lazy_loading.dart';
import 'package:test_sa/views/widgets/loaders/no_data_found.dart';
import 'package:test_sa/views/widgets/notifications/notification_item.dart';

class NotificationsList extends StatelessWidget {
  final List<SystemNotificationModel> notifications;
  final bool nextPage;
  final Future<void> Function() onLazyLoad;

  const NotificationsList({Key? key, this.notifications = const <SystemNotificationModel>[], required this.nextPage, required this.onLazyLoad}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (notifications.isEmpty) {
      return NoDataFound(message: context.translation.notificationsNotFound).center;
    }
    return LazyLoading(
      nextPage: nextPage,
      onLazyLoad: onLazyLoad,
      child: SingleChildScrollView(
        padding: const EdgeInsets.all(16),
        child: ListView.separated(
          shrinkWrap: true,
          physics: const NeverScrollableScrollPhysics(),
          padding: const EdgeInsets.all(0),
          itemCount: notifications.length,
          separatorBuilder: (context, itemIndex) => const Divider().defaultStyle(context).paddingOnly(top: 16, bottom: 16),
          itemBuilder: (context, itemIndex) {
            return NotificationItem(
              notification: notifications[itemIndex],
              onPressed: (notification) {
                FirebaseNotificationManger.handleMessage(context, notification.toNotificationJson());
              },
            );
          },
        ).toShadowContainer(context),
      ),
    );
  }
}
