import 'dart:io';

import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';

class ImagePreviewCard extends StatelessWidget {
  final bool imageFileExists;
  final File imageFile;
  final VoidCallback onTap;

  const ImagePreviewCard({
    super.key,
    required this.imageFileExists,
    required this.imageFile,
    required this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return Stack(
      clipBehavior: Clip.none,
      children: [
        Container(
          width: 30.w,
          height: 30.w,
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(2.5.w),
            border: Border.all(color: Colors.grey.shade300),
            color: Colors.grey[200],
          ),
          child: imageFileExists
              ? ClipRRect(
                  borderRadius: BorderRadiusGeometry.circular(2.5.w),
                  child: Image.file(
                    imageFile,
                    fit: BoxFit.cover,
                    width: double.infinity,
                    height: double.infinity,
                    errorBuilder: (context, error, stackTrace) {
                      return Icon(
                        Icons.error,
                        color: Colors.grey[400],
                        size: 8.w,
                      );
                    },
                  ),
                )
              : Icon(Icons.image, color: Colors.grey[400], size: 8.w),
        ),

        Positioned(
          top: 1.w,
          right: 1.w,
          child: Material(
            color: Colors.transparent,
            type: MaterialType.transparency,
            child: InkWell(
              onTap: onTap,
              child: Container(
                padding: EdgeInsets.all(1.w),
                decoration: BoxDecoration(
                  color: Colors.red[50],
                  shape: BoxShape.circle,
                  border: Border.all(color: Colors.red.withOpacity(0.2)),
                  boxShadow: [
                    BoxShadow(
                      color: Colors.black.withOpacity(0.1),
                      blurRadius: 2,
                      offset: Offset(0, 1),
                    ),
                  ],
                ),
                child: Icon(Icons.remove, color: Colors.red, size: 4.w),
              ),
            ),
          ),
        ),
      ],
    );
  }
}
