import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class CustomCachedImage extends StatelessWidget {
  final String imageUrl;
  final double? width;
  final double? height;
  final BoxFit fit;
  final double borderRadius;
  final Widget? placeholder;
  final Widget? errorWidget;

  const CustomCachedImage({
    super.key,
    required this.imageUrl,
    this.width,
    this.height,
    this.fit = BoxFit.cover,
    this.borderRadius = 0,
    this.placeholder,
    this.errorWidget,
  });

  @override
  Widget build(BuildContext context) {
    return ClipRRect(
      borderRadius: BorderRadius.circular(borderRadius),
      child: CachedNetworkImage(
        imageUrl: imageUrl,
        width: width,
        height: height,
        fit: fit,
        placeholder: (context, url) =>
        placeholder ?? _defaultPlaceholder(),
        errorWidget: (context, url, error) =>
        errorWidget ?? _defaultErrorWidget(),
      ),
    );
  }

  Widget _defaultPlaceholder() {
    return Center(
      child: CupertinoActivityIndicator(),
    );
  }

  Widget _defaultErrorWidget() {
    return Center(
      child: Image.asset("sc_images/general/sc_icon_loading.png"),
    );
  }
}