import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gap/gap.dart';
import 'package:image_picker/image_picker.dart';
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
import 'package:krow/core/presentation/styles/theme.dart';
import 'package:krow/core/presentation/widgets/ui_kit/kw_button.dart';
import 'package:krow/features/profile/live_photo/domain/bloc/live_photo_bloc.dart';

class PhotoRequirementsCard extends StatelessWidget {
  const PhotoRequirementsCard({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(12),
      decoration: const BoxDecoration(
        color: AppColors.grayWhite,
        borderRadius: BorderRadius.all(
          Radius.circular(12),
        ),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
           Text(
            'ensure_meet_requirements'.tr(),
            style: AppTextStyles.bodyMediumMed,
          ),
          const Gap(12),
          Column(
            spacing: 8,
            children: [
              for (int i = 0; i < requirementsData.length; i++)
                Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Container(
                      height: 20,
                      width: 20,
                      alignment: Alignment.center,
                      decoration: const BoxDecoration(
                        shape: BoxShape.circle,
                        color: AppColors.bgColorDark,
                      ),
                      child: Text(
                        '${i + 1}',
                        style: const TextStyle(
                          fontFamily: 'Poppins',
                          fontWeight: FontWeight.w500,
                          fontSize: 8,
                          color: AppColors.grayWhite,
                        ),
                      ),
                    ),
                    const Gap(8),
                    Expanded(
                      child: Text(
                        requirementsData[i].tr(),
                        style: AppTextStyles.bodySmallReg,
                      ),
                    ),
                  ],
                ),
            ],
          ),
          const Gap(16),
          BlocSelector<LivePhotoBloc, LivePhotoState, bool>(
            selector: (state) => state.photoData != null,
            builder: (context, isPhotoTaken) {
              return KwButton.primary(
                label: isPhotoTaken?'take_new_photo'.tr():'take_photo'.tr(),
                onPressed: () {
                  ImagePicker()
                      .pickImage(
                    source: ImageSource.camera,
                    preferredCameraDevice: CameraDevice.front,
                  )
                      .then(
                    (photo) {
                      if (photo == null || !context.mounted) return;

                      context.read<LivePhotoBloc>().add(
                            AddNewPhotoEvent(newImagePath: photo.path),
                          );
                    },
                  );
                },
              );
            },
          ),
        ],
      ),
    );
  }
}

const requirementsData = [
  'stand_in_well_lit_area',
  'ensure_face_visible',
  'avoid_filters_obstructions',
];
