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

class FloorSelector extends StatelessWidget {
  final List<String> floorNames;
  final int selectedIndex;

  const FloorSelector({
    super.key,
    required this.floorNames,
    required this.selectedIndex,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      child: SingleChildScrollView(
        scrollDirection: Axis.horizontal,
        padding: EdgeInsets.symmetric(horizontal: 28.w, vertical: 16.h),
        child: Row(
          children: floorNames.asMap().entries.map((entry) {
            final index = entry.key;
            final name = entry.value;
            final isSelected = index == selectedIndex;
            return Padding(
              padding: EdgeInsets.only(right: 32.w),
              child: GestureDetector(
                onTap: () {
                  context.read<RoomReportCubit>().selectFloor(index);
                },
                child: Column(
                  children: [
                    Text(
                      name,
                      style: TextStyle(
                        fontSize: 28.sp,
                        color: isSelected
                            ? const Color.fromRGBO(59, 130, 246, 1)
                            : const Color.fromRGBO(156, 163, 175, 1),
                        fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
                      ),
                    ),
                    SizedBox(height: 4.h),
                    Container(
                      width: 40.w,
                      height: 3.h,
                      decoration: BoxDecoration(
                        color: isSelected
                            ? const Color.fromRGBO(59, 130, 246, 1)
                            : Colors.transparent,
                        borderRadius: BorderRadius.circular(2.r),
                      ),
                    ),
                  ],
                ),
              ),
            );
          }).toList(),
        ),
      ),
    );
  }
}
