import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:image_picker/image_picker.dart';
import 'package:krow/core/application/common/date_time_extension.dart';
import 'package:krow/core/presentation/styles/theme.dart';
import 'package:krow/core/presentation/widgets/uploud_image_card.dart';
import 'package:krow/features/profile/live_photo/domain/bloc/live_photo_bloc.dart';
import 'package:krow/features/profile/live_photo/data/models/live_photo_data.dart';

class LivePhotoDisplayCard extends StatelessWidget {
  const LivePhotoDisplayCard({
    super.key,
    required this.photoData,
  });

  final LivePhotoData photoData;

  String _getPhotoStatus(LivePhotoStatus status) {
    return switch (status) {
      LivePhotoStatus.pending => 'Pending'.tr(),
      LivePhotoStatus.verified => 'Verified'.tr(),
      LivePhotoStatus.declined => 'Declined'.tr(),
    };
  }

  Color _getPhotoStatusColor(LivePhotoStatus status) {
    return switch (status) {
      LivePhotoStatus.pending => AppColors.primaryBlue,
      LivePhotoStatus.verified => AppColors.statusSuccess,
      LivePhotoStatus.declined => AppColors.statusError,
    };
  }

  @override
  Widget build(BuildContext context) {
    return UploadImageCard(
      title: '${'Photo'.tr()} ${photoData.timestamp.toDayMonthYearString()}',
      imageUrl: photoData.imageUrl,
      localImagePath: photoData.imagePath,
      message: _getPhotoStatus(photoData.status),
      statusColor: _getPhotoStatusColor(photoData.status),
      onDeleteTap: () {
        context.read<LivePhotoBloc>().add(const DeleteCurrentPhotoEvent());
      },
      onSelectImage: () {
        ImagePicker()
            .pickImage(
          source: ImageSource.camera,
          preferredCameraDevice: CameraDevice.front,
        )
            .then(
          (photo) {
            if (photo == null || !context.mounted) return;

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