import 'package:flutter/material.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/extensions/int_extensions.dart';
import 'package:test_sa/extensions/string_extensions.dart';
import 'package:test_sa/extensions/text_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/models/system_notification_model.dart';
import 'package:test_sa/new_views/app_style/app_color.dart';
import 'package:test_sa/views/widgets/item_views/info_date_widget.dart';
import 'package:test_sa/views/widgets/item_views/info_header_widget.dart';
import 'package:test_sa/views/widgets/item_views/info_text_widget.dart';
import 'package:test_sa/views/widgets/requests/request_status.dart';

class NotificationItem extends StatelessWidget {
  final SystemNotificationModel notification;
  final Function(SystemNotificationModel) onPressed;

  bool isLoading;

  NotificationItem({Key? key, required this.notification, required this.onPressed, this.isLoading = false}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          children: [
            if (notification.priorityName != null)
              StatusLabel(
                label: notification.priorityName,
                textColor: AppColor.getRequestStatusTextColorByName(context, notification.priorityName!),
                backgroundColor: AppColor.getRequestStatusColorByName(context, notification.priorityName!),
              ).toShimmer(isShow: isLoading, context: context),
            8.width,
            if ((notification.statusName ?? "").isNotEmpty && notification.sourceName != "Asset Transfer")
              StatusLabel(
                label: notification.statusName ?? "",
                textColor: AppColor.getRequestStatusTextColorByName(context, notification.statusName ?? ""),
                backgroundColor: AppColor.getRequestStatusColorByName(context, notification.statusName ?? ""),
              ).toShimmer(isShow: isLoading, context: context),
          ],
        ),
        8.height,
        Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            InfoHeaderWidget(notification.title ?? "").toShimmer(isShow: isLoading, context: context).expanded,
            8.width,
            if (notification.createdOn?.isNotEmpty ?? false) InfoDateWidget(notification.createdOn!).toShimmer(isShow: isLoading, context: context),
          ],
        ),
        InfoTextWidget(label: notification.text ?? "", isMsg: true, showEmptyValue: true).toShimmer(isShow: isLoading, context: context),
      ],
    ).onPress(() {
      onPressed(notification);
    });
  }
}
