// lib/features/admin/tabs/kpi/sharp_kpi_card.dart

import 'package:flutter/material.dart';

class SharpKpiCard extends StatelessWidget {
  final String title;
  final String value;
  final String subtitle;
  final IconData icon;
  final Color iconColor;
  final bool isFailing;
  final String? targetValue;

  const SharpKpiCard({
    super.key,
    required this.title,
    required this.value,
    required this.subtitle,
    required this.icon,
    required this.iconColor,
    this.isFailing = false,
    this.targetValue,
  });

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (context, constraints) {
        // Adapt padding and font size for very small screens
        final isCompact = constraints.maxWidth < 200;
        
        return Container(
          padding: EdgeInsets.all(isCompact ? 12.0 : 24.0),
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.zero, // Strict sharp edges
            border: Border.all(color: Colors.grey.shade200, width: 1),
            boxShadow: [
              BoxShadow(
                color: Colors.black.withOpacity(0.02),
                blurRadius: 10,
                offset: const Offset(0, 4),
              ),
            ],
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Expanded(
                    child: Text(
                      title.toUpperCase(),
                      maxLines: 2,
                      overflow: TextOverflow.ellipsis,
                      style: TextStyle(
                        fontSize: isCompact ? 10 : 12,
                        fontWeight: FontWeight.bold,
                        color: Colors.grey.shade500,
                        letterSpacing: 1.0,
                      ),
                    ),
                  ),
                  if (!isCompact) ...[
                    const SizedBox(width: 8),
                    Icon(icon, color: iconColor, size: 24),
                  ]
                ],
              ),
              SizedBox(height: isCompact ? 8 : 16),
              Row(
                crossAxisAlignment: CrossAxisAlignment.end,
                children: [
                  Text(
                    value,
                    style: TextStyle(
                      fontSize: isCompact ? 22 : 32,
                      fontWeight: FontWeight.w900,
                      color: isFailing ? Colors.redAccent : Colors.black87,
                    ),
                  ),
                  if (targetValue != null) ...[
                    const SizedBox(width: 8),
                    Padding(
                      padding: const EdgeInsets.only(bottom: 4.0),
                      child: Text(
                        '/ $targetValue',
                        style: TextStyle(
                          fontSize: isCompact ? 11 : 13,
                          fontWeight: FontWeight.w600,
                          color: Colors.grey.shade400,
                        ),
                      ),
                    ),
                  ]
                ],
              ),
              SizedBox(height: isCompact ? 4 : 8),
              Text(
                subtitle,
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(
                  fontSize: isCompact ? 11 : 13,
                  fontWeight: FontWeight.w500,
                  color: isFailing ? Colors.redAccent : Colors.grey.shade600,
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}