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

import '../../../core/theme/colors.dart';
import 'notification_card.dart';

class NotificationAllTab extends StatelessWidget {
  const NotificationAllTab({this.scrollController, super.key});

  final ScrollController? scrollController;

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

    if (viewModel.isLoadingAll &&
        (viewModel.allNotificationResponse?.data?.isEmpty ?? true)) {
      return const Center(
        child: CircularProgressIndicator(color: AppColors.cyanTeal),
      );
    }

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

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

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