import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:tm_app/core/utils/size_config.dart';
import 'package:tm_app/view_models/notification_view_model.dart';
import 'package:tm_app/views/notification/strings/notification_strings.dart';

import 'notification_card.dart';

class NotificationUnreadTab extends StatelessWidget {
  final ScrollController? scrollController;
  const NotificationUnreadTab({this.scrollController, super.key});

  @override
  Widget build(BuildContext context) {
    final viewModel = context.watch<NotificationViewModel>();

    if (viewModel.isLoadingUnread){
      return const Center(child: CircularProgressIndicator());
    }

    final notifications =
        viewModel.unreadNotificationResponse?.data ?? [];

    if (notifications.isEmpty) {
      return const Center(child: Text(NotificationStrings.noUnreadNotifications,));
    }

    return ListView.builder(
      controller: scrollController,
      itemCount: notifications.length,
      itemBuilder: (context, index) {
        final notification = notifications[index];
        return Padding(
          padding: EdgeInsets.only(bottom: 16.0.h()),
          child: NotificationCard(notification: notification),
        );
      },
    );
  }
}
