// lib/features/attendance/widgets/attendance_history_card.dart

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:smpn1_lengkong/core/constants/app_colors.dart';
import 'package:smpn1_lengkong/core/models/attendance_log_model.dart';

class AttendanceHistoryCard extends StatelessWidget {
  final AttendanceLog log;

  const AttendanceHistoryCard({super.key, required this.log});

  @override
  Widget build(BuildContext context) {
    Color statusColor;

    // PERBAIKAN: Menambahkan logika warna untuk status 'Hadir'
    switch (log.status) {
      case 'Hadir':
        statusColor = AppColors.successGreen; // Warna Hijau dari konstanta
        break;
      case 'Sakit':
        statusColor = Colors.orange;
        break;
      case 'Izin':
        statusColor = Colors.blue;
        break;
      case 'Alpha':
        statusColor = AppColors.dangerRed; // Warna Merah
        break;
      default:
        statusColor = Colors.grey;
    }

    return Container(
      margin: EdgeInsets.only(bottom: 12.h),
      padding: EdgeInsets.all(16.w),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(12.r),
        // Garis samping akan otomatis mengikuti warna statusColor (termasuk hijau jika Hadir)
        border: Border(left: BorderSide(color: statusColor, width: 4)),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.05),
            blurRadius: 5,
            offset: const Offset(0, 2),
          ),
        ],
      ),
      child: Row(
        children: [
          Container(
            padding: EdgeInsets.all(8.w),
            decoration: BoxDecoration(
              color: statusColor.withOpacity(0.1),
              shape: BoxShape.circle,
            ),
            child: Icon(Icons.calendar_today, color: statusColor, size: 20.sp),
          ),
          SizedBox(width: 16.w),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  log.date.toString().substring(0, 10),
                  style: TextStyle(fontSize: 12.sp, color: Colors.grey),
                ),
                SizedBox(height: 4.h),
                Text(
                  log.status,
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                    fontSize: 16.sp,
                    color: AppColors.textPrimary, // Warna teks utama
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
