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

class RoomInfoBlock extends StatelessWidget {
  final Map<String, dynamic> roomDetail;
  final Map<String, dynamic> roomStatus;

  const RoomInfoBlock({
    super.key,
    required this.roomDetail,
    required this.roomStatus,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      padding: EdgeInsets.all(20.w),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(24.r),
        color: Colors.white,
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                '${roomDetail['roomNumber']}号房',
                style: TextStyle(
                  fontSize: 36.sp,
                  fontWeight: FontWeight.bold,
                  color: const Color.fromRGBO(31, 41, 55, 1),
                ),
              ),
              Container(
                padding:
                    EdgeInsets.symmetric(horizontal: 16.w, vertical: 6.h),
                decoration: BoxDecoration(
                  color: _getStatusColor(roomDetail['status'] as String),
                  borderRadius: BorderRadius.circular(12.r),
                ),
                child: Text(
                  roomDetail['status'] as String,
                  style: TextStyle(
                    fontSize: 22.sp,
                    color: Colors.white,
                  ),
                ),
              ),
            ],
          ),
          SizedBox(height: 16.h),
          _buildInfoRow(
              '房型', roomDetail['roomType'] as String),
          _buildInfoRow(
              '住客', roomDetail['guestName'] as String? ?? '无'),
          if (roomDetail['checkInDate'] != null) ...[
            _buildInfoRow(
                '入住日期', roomDetail['checkInDate'] as String),
            _buildInfoRow(
                '预计退房', roomDetail['checkOutDate'] as String),
          ],
          SizedBox(height: 16.h),
          _buildInfoRow(
              '当前功率', roomStatus['currentPower'] as String),
          _buildInfoRow('WiFi信号',
              '${roomStatus['wifiSignal'] as String} (${roomStatus['wifiNormal'] as bool ? '正常' : '异常'})'),
          _buildInfoRow(
              '刷新时间', roomStatus['guestRefreshTime'] as String),
        ],
      ),
    );
  }

  Widget _buildInfoRow(String label, String value) {
    return Padding(
      padding: EdgeInsets.only(bottom: 8.h),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            label,
            style: TextStyle(
              fontSize: 24.sp,
              color: const Color.fromRGBO(107, 114, 128, 1),
            ),
          ),
          Text(
            value,
            style: TextStyle(
              fontSize: 24.sp,
              color: const Color.fromRGBO(31, 41, 55, 1),
            ),
          ),
        ],
      ),
    );
  }

  Color _getStatusColor(String status) {
    switch (status) {
      case '入住中':
        return const Color.fromRGBO(34, 197, 94, 1);
      case '空闲':
        return const Color.fromRGBO(59, 130, 246, 1);
      case '待清洁':
        return const Color.fromRGBO(251, 191, 36, 1);
      default:
        return const Color.fromRGBO(107, 114, 128, 1);
    }
  }
}