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

enum AttendanceType { checkin, checkout, breaks, days }

class AttendanceCard extends StatelessWidget {
  const AttendanceCard({
    super.key,
    required this.type,
    required this.title,
    required this.value,
    required this.subtitle,
    this.scheduledTime,
  });
  final AttendanceType type;
  final String title;
  final String value;
  final String subtitle;
  final String? scheduledTime;

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

    return Container(
      padding: const EdgeInsets.all(UiConstants.space3),
      decoration: BoxDecoration(
        color: UiColors.white,
        borderRadius: UiConstants.radiusLg,
        border: Border.all(color: UiColors.bgSecondary),
        boxShadow: <BoxShadow>[
          BoxShadow(
            color: UiColors.black.withValues(alpha: 0.05),
            blurRadius: 2,
            offset: const Offset(0, 1),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Container(
            width: 32,
            height: 32,
            decoration: BoxDecoration(
              color: styles.bgColor,
              borderRadius: UiConstants.radiusMd,
            ),
            child: Icon(styles.icon, size: 16, color: styles.iconColor),
          ),
          const SizedBox(height: UiConstants.space2),
          Text(
            title,
            style: UiTypography.titleUppercase4m.textSecondary,
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
          ),
          const SizedBox(height: 2),
          FittedBox(
            fit: BoxFit.scaleDown,
            child: Text(
              value,
              style: UiTypography.headline4m,
            ),
          ),
          if (scheduledTime != null) ...<Widget>[
            const SizedBox(height: 2),
            Text(
              "Scheduled: $scheduledTime",
              style: UiTypography.footnote2r.textInactive,
            ),
          ],
          const SizedBox(height: 2),
          Text(
            subtitle,
            style: UiTypography.footnote1r.copyWith(color: UiColors.primary),
          ),
        ],
      ),
    );
  }

  _AttendanceStyle _getStyles(AttendanceType type) {
    switch (type) {
      case AttendanceType.checkin:
        return _AttendanceStyle(
          icon: UiIcons.logIn,
          bgColor: UiColors.primary.withValues(alpha: 0.1),
          iconColor: UiColors.primary,
        );
      case AttendanceType.checkout:
        return _AttendanceStyle(
          icon: UiIcons.logOut,
          bgColor: UiColors.foreground.withValues(alpha: 0.1),
          iconColor: UiColors.foreground,
        );
      case AttendanceType.breaks:
        return _AttendanceStyle(
          icon: UiIcons.coffee,
          bgColor: UiColors.accent.withValues(alpha: 0.2),
          iconColor: UiColors.accentForeground,
        );
      case AttendanceType.days:
        return _AttendanceStyle(
          icon: UiIcons.calendar,
          bgColor: UiColors.success.withValues(alpha: 0.1),
          iconColor: UiColors.textSuccess,
        );
    }
  }
}

class _AttendanceStyle {

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