import 'package:digiplug/bat_theme/bat_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class RoomCard extends StatelessWidget {
  final String roomName;
  final int deviceCount;
  final VoidCallback? onTap;

  const RoomCard({
    super.key,
    required this.roomName,
    required this.deviceCount,
    this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    var theme = BatThemeData.of(context);

    IconData getIconForRoom(String name) {
      switch (name.toLowerCase()) {
        case 'kamar tidur':
          return Icons.king_bed_outlined;
        case 'dapur':
          return Icons.kitchen_outlined;
        case 'ruang keluarga':
          return Icons.living_outlined;
        case 'teras':
          return Icons.deck_outlined;
        default:
          return Icons.home_work_outlined;
      }
    }

    return GestureDetector(
      onTap: onTap,
      child: Container(
        padding: EdgeInsets.all(16.r),
        decoration: BoxDecoration(
          color: theme.colors.tertiary.withOpacity(0.1),
          borderRadius: BorderRadius.circular(20.r),
          border: Border.all(
            color: theme.colors.tertiary.withOpacity(0.2),
            width: 1,
          ),
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Icon(
              getIconForRoom(roomName),
              color: theme.colors.primary,
              size: 40.w,
            ),
            const Spacer(),
            Text(
              roomName,
              style: theme.typography.bodyCopyMedium,
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
            ),
            SizedBox(height: 4.h),
            Text(
              '$deviceCount Perangkat',
              style: theme.typography.subtitle
                  .copyWith(color: theme.colors.tertiary.withOpacity(0.7)),
            ),
          ],
        ),
      ),
    );
  }
}
