import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class Transaction {
  final String id;
  final String title;
  final double amount;
  final DateTime date;
  final String type;
  final String status;
  final IconData icon;

  Transaction({
    required this.id,
    required this.title,
    required this.amount,
    required this.date,
    required this.type,
    required this.status,
    required this.icon,
  });
}

class TransactionProvider with ChangeNotifier {
  final List<Transaction> _transactions = [
    Transaction(
      id: '1',
      title: 'Electricity Bill',
      amount: -120.00,
      date: DateTime.now().subtract(const Duration(days: 0)),
      type: 'Bill',
      status: 'Completed',
      icon: Icons.electric_bolt,
    ),
    Transaction(
      id: '2',
      title: 'Internet Bill',
      amount: -75.00,
      date: DateTime.now().subtract(const Duration(days: 1)),
      type: 'Bill',
      status: 'Completed',
      icon: Icons.wifi,
    ),
    Transaction(
      id: '3',
      title: 'Mobile Bill',
      amount: -50.00,
      date: DateTime.now().subtract(const Duration(days: 2)),
      type: 'Bill',
      status: 'Completed',
      icon: Icons.phone_android,
    ),
    Transaction(
      id: '4',
      title: 'Water Bill',
      amount: -45.00,
      date: DateTime.now().subtract(const Duration(days: 3)),
      type: 'Bill',
      status: 'Completed',
      icon: Icons.water_drop,
    ),
    Transaction(
      id: '5',
      title: 'Gas Bill',
      amount: -65.00,
      date: DateTime.now().subtract(const Duration(days: 4)),
      type: 'Bill',
      status: 'Completed',
      icon: Icons.local_fire_department,
    ),
  ];

  double _balance = 2450.00;

  List<Transaction> get transactions => _transactions;
  double get balance => _balance;

  void addTransaction(Transaction transaction) {
    _transactions.insert(0, transaction);
    _balance += transaction.amount;
    notifyListeners();
  }

  void removeTransaction(String id) {
    final transaction = _transactions.firstWhere((t) => t.id == id);
    _transactions.removeWhere((t) => t.id == id);
    _balance -= transaction.amount;
    notifyListeners();
  }

  List<Transaction> getTransactionsByType(String type) {
    if (type == 'All') return _transactions;
    return _transactions.where((t) => t.type == type).toList();
  }

  String getFormattedDate(DateTime date) {
    final now = DateTime.now();
    final difference = now.difference(date);

    if (difference.inDays == 0) {
      return 'Today';
    } else if (difference.inDays == 1) {
      return 'Yesterday';
    } else if (difference.inDays < 7) {
      return '${difference.inDays} days ago';
    } else {
      return '${date.day}/${date.month}/${date.year}';
    }
  }
} 