import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_web/utils/constants/assets.dart';
import 'package:syncrow_web/utils/extension/build_context_x.dart';
import 'package:syncrow_web/pages/device_managment/shared/device_controls_container.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/model/ceiling_sensor_model.dart';

class PresenceSpaceType extends StatelessWidget {
  const PresenceSpaceType({
    super.key,
    required this.description,
    required this.value,
    required this.action,
  });

  final String description;
  final SpaceTypes value;
  final void Function(String value) action;

  @override
  Widget build(BuildContext context) {
    final Map<SpaceTypes, String> spaceTypeIcons = {
      SpaceTypes.none: Assets.office,
      SpaceTypes.parlour: Assets.parlour,
      SpaceTypes.area: Assets.dyi,
      SpaceTypes.toilet: Assets.bathroom,
      SpaceTypes.bedroom: Assets.bedroom,
    };

    return DeviceControlsContainer(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            description,
            style: context.textTheme.bodySmall!.copyWith(
              color: ColorsManager.blackColor,
              fontWeight: FontWeight.w400,
              fontSize: 10,
            ),
          ),
          const SizedBox(
            height: 8,
          ),
          Wrap(
            runSpacing: 8,
            spacing: 16,
            children: spaceTypeIcons.entries.map((entry) {
              final icon = entry.value;
              final spaceType = entry.key;
              return GestureDetector(
                onTap: () => action(spaceType.name),
                child: Container(
                  width: 40,
                  height: 40,
                  padding: const EdgeInsets.all(8),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(100),
                    color: value == spaceType
                        ? ColorsManager.primaryColorWithOpacity
                        : ColorsManager.textGray,
                  ),
                  child: SvgPicture.asset(
                    icon,
                    width: 25,
                    height: 22,
                  ),
                ),
              );
            }).toList(),
          ),
        ],
      ),
    );
  }
}
