import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:smart_hotel_app/views/report/room/cubit/room_report_state.dart';

class RoomGrid extends StatelessWidget {
  final List<RoomInfo> rooms;

  const RoomGrid({super.key, required this.rooms});

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      padding: EdgeInsets.symmetric(horizontal: 28.w),
      child: GridView.count(
        shrinkWrap: true,
        physics: const NeverScrollableScrollPhysics(),
        crossAxisCount: 5,
        mainAxisSpacing: 20.h,
        crossAxisSpacing: 16.w,
        children: rooms.map((room) => RoomItem(room: room)).toList(),
      ),
    );
  }
}

class RoomItem extends StatelessWidget {
  final RoomInfo room;

  const RoomItem({super.key, required this.room});

  Color get _bgColor {
    switch (room.status) {
      case RoomStatus.vacant:
        return const Color.fromRGBO(229, 231, 235, 1);
      case RoomStatus.occupied:
      case RoomStatus.reserved:
        return const Color.fromRGBO(219, 234, 254, 1);
      case RoomStatus.warning:
      case RoomStatus.temperature:
        return const Color.fromRGBO(254, 243, 199, 1);
    }
  }

  Color get _textColor {
    switch (room.status) {
      case RoomStatus.vacant:
        return const Color.fromRGBO(156, 163, 175, 1);
      case RoomStatus.occupied:
      case RoomStatus.reserved:
        return const Color.fromRGBO(59, 130, 246, 1);
      case RoomStatus.warning:
      case RoomStatus.temperature:
        return const Color.fromRGBO(245, 158, 11, 1);
    }
  }

  Color? get _borderColor {
    switch (room.status) {
      case RoomStatus.vacant:
        return null;
      case RoomStatus.occupied:
      case RoomStatus.reserved:
        return const Color.fromRGBO(59, 130, 246, 1);
      case RoomStatus.warning:
      case RoomStatus.temperature:
        return const Color.fromRGBO(245, 158, 11, 1);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 12.h, horizontal: 8.w),
      decoration: BoxDecoration(
        color: _bgColor,
        borderRadius: BorderRadius.circular(16.r),
        border: _borderColor != null
            ? Border.all(color: _borderColor!, width: 2.w)
            : null,
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Text(
            room.roomNumber,
            style: TextStyle(
              fontSize: 28.sp,
              fontWeight: FontWeight.bold,
              color: _textColor,
            ),
          ),
          SizedBox(height: 4.h),
          if (room.status == RoomStatus.warning || room.status == RoomStatus.temperature)
            Icon(Icons.warning_amber_outlined, color: _textColor, size: 20.sp),
          if (room.status != RoomStatus.warning && room.status != RoomStatus.temperature)
            Text(
              room.statusText,
              style: TextStyle(
                fontSize: 20.sp,
                color: _textColor,
              ),
            ),
        ],
      ),
    );
  }
}
