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

enum AttendanceType { checkin, checkout, breaks, days }

class AttendanceCard extends StatelessWidget {
  final AttendanceType type;
  final String title;
  final String value;
  final String subtitle;
  final String? scheduledTime;

  const AttendanceCard({
    super.key,
    required this.type,
    required this.title,
    required this.value,
    required this.subtitle,
    this.scheduledTime,
  });

  @override
  Widget build(BuildContext context) {
    final styles = _getStyles(type);

    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(16),
        border: Border.all(color: Colors.grey.shade100),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.05),
            blurRadius: 2,
            offset: const Offset(0, 1),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            width: 36,
            height: 36,
            decoration: BoxDecoration(
              color: styles.bgColor,
              borderRadius: BorderRadius.circular(12),
            ),
            child: Icon(styles.icon, size: 16, color: styles.iconColor),
          ),
          const SizedBox(height: 12),
          Text(
            title,
            style: const TextStyle(
              fontSize: 12,
              color: Color(0xFF64748B), // slate-500
            ),
          ),
          const SizedBox(height: 4),
          Text(
            value,
            style: const TextStyle(
              fontSize: 20,
              fontWeight: FontWeight.bold,
              color: Color(0xFF0F172A), // slate-900
            ),
          ),
          if (scheduledTime != null) ...[
            const SizedBox(height: 2),
            Text(
              "Scheduled: $scheduledTime",
              style: const TextStyle(
                fontSize: 10,
                color: Color(0xFF94A3B8), // slate-400
              ),
            ),
          ],
          const SizedBox(height: 2),
          Text(
            subtitle,
            style: const TextStyle(fontSize: 12, color: Color(0xFF0032A0)),
          ),
        ],
      ),
    );
  }

  _AttendanceStyle _getStyles(AttendanceType type) {
    switch (type) {
      case AttendanceType.checkin:
        return _AttendanceStyle(
          icon: LucideIcons.logIn,
          bgColor: const Color(0xFF0032A0).withOpacity(0.1),
          iconColor: const Color(0xFF0032A0),
        );
      case AttendanceType.checkout:
        return _AttendanceStyle(
          icon: LucideIcons.logOut,
          bgColor: const Color(0xFF333F48).withOpacity(0.1),
          iconColor: const Color(0xFF333F48),
        );
      case AttendanceType.breaks:
        return _AttendanceStyle(
          icon: LucideIcons.coffee,
          bgColor: const Color(0xFFF9E547).withOpacity(0.2),
          iconColor: const Color(0xFF4C460D),
        );
      case AttendanceType.days:
        return _AttendanceStyle(
          icon: LucideIcons.calendar,
          bgColor: Colors.green.withOpacity(0.1),
          iconColor: Colors.green,
        );
    }
  }
}

class _AttendanceStyle {
  final IconData icon;
  final Color bgColor;
  final Color iconColor;

  _AttendanceStyle({
    required this.icon,
    required this.bgColor,
    required this.iconColor,
  });
}
