import 'package:flutter/material.dart';
import 'package:garage/utils/date_time_utils.dart';

import 'expiry_colors.dart';

Color? getColorFromDate(BuildContext context, DateTime? date) {
  if (date == null) {
    return null;
  }
  final expiryColors = Theme.of(context).extension<ExpiryColors>()!;

  if (date.isBefore(DateTime.now())) {
    return expiryColors.expired;
  }
  if (date.isBefore(DateTime.now().add(Duration(days: 30)))) {
    return expiryColors.monthLess;
  }
  return null;
}

Text getStyledDateAsText(BuildContext context, DateTime? date) {
  final color = getColorFromDate(context, date);
  return Text(
    getPrettyDate(date),
    style: TextStyle(
      color: color,
      fontWeight: color == null ? null : FontWeight.bold,
    ),
  );
}
