import 'package:comwell_key_app/presentation/screens/house_keeping/cubit/housekeeping_cubit.dart';
import 'package:comwell_key_app/themes/light_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/svg.dart';
import 'housekeeping_service.dart';

class SelectableService extends StatelessWidget {
  final HouseKeepingService service;

  const SelectableService({super.key, required this.service});

  @override
  Widget build(BuildContext context) {
    final cubit = context.read<HouseKeepingCubit>();
    final isSelected = cubit.state.selectedServices.contains(service.name);
    return InkWell(
      onTap: () {
        cubit.onServiceClicked(service.name);
      },
      borderRadius: const BorderRadius.all(Radius.circular(5)),
      child: Container(
        decoration: BoxDecoration(
          border: Border.all(
            color: colorDivider,
          ),
          borderRadius: const BorderRadius.all(Radius.circular(10)),
        ),
        child: Padding(
          padding: const EdgeInsets.all(12.0),
          child: Row(
            children: [
              Container(
                height: service == HouseKeepingService.cleaning ? 48 : 36,
                width: 36,
                decoration: const BoxDecoration(
                  color: colorSecondary,
                  shape: BoxShape.circle,
                ),
                child: Padding(
                  padding: const EdgeInsets.all(10.0),
                  child: SvgPicture.asset(service.assetId),
                ),
              ),
              const SizedBox(width: 12),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      service.titleStringId(context),
                      style: Theme.of(context).textTheme.bodySmall,
                      maxLines: 1,
                      overflow: TextOverflow.clip,
                    ),
                    if (service == HouseKeepingService.cleaning)
                      Text(service.subtitleStringId(context),
                          maxLines: 2,
                          style: Theme.of(context)
                              .textTheme
                              .bodySmall
                              ?.copyWith(color: Colors.grey),
                          overflow: TextOverflow.clip),
                  ],
                ),
              ),
              const SizedBox(width: 12),
              if (isSelected)
                SvgPicture.asset(
                  "assets/icons/ic_checkmark.svg",
                  height: 24,
                  width: 24,
                )
              else
                Container(
                  height: 24,
                  width: 24,
                  decoration: BoxDecoration(
                    border: Border.all(
                      color: colorDivider,
                    ),
                    shape: BoxShape.circle,
                  ),
                )
            ],
          ),
        ),
      ),
    );
  }
}