import 'package:comwell_key_app/common/const.dart';
import 'package:comwell_key_app/up_sales/components/background_animation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';

class UpsaleHeaderMedia extends StatelessWidget {
  final double height;  
  final String? animationJson;
  final String? backgroundImageUrl;
  final bool shouldHavePadding;
  final List<String>? images;

  const UpsaleHeaderMedia({super.key, this.height = 180, this.images, this.shouldHavePadding = true, this.animationJson, this.backgroundImageUrl});

  @override
  Widget build(BuildContext context) {  
    return ClipRRect(
      borderRadius: const BorderRadius.only(
        topLeft: Radius.circular(10),
        topRight: Radius.circular(10),
      ),
      child: Builder(
        builder: (context) {
          if (animationJson != null && backgroundImageUrl != null) {
            return Padding(
              padding: shouldHavePadding ? const EdgeInsets.only(top: 100) : EdgeInsets.zero,
              child: SizedBox(
                height: height * (shouldHavePadding ? 0.3 : 1),
                width: double.infinity,
                child: IgnorePointer(
                  child: BackgroundAnimation(animationJson: animationJson!, backgroundImageUrl: backgroundImageUrl!),
                ),
              ),
            );
          } else if (images?.isNotEmpty ?? false) {
            return Image.network(
              images?.first ?? '',
              height: height,
              width: double.infinity,
              fit: BoxFit.cover,
            );
          } else {
            return Image.asset(
              kPlaceholderImage,
              height: height,
              width: double.infinity,
              fit: BoxFit.cover,
            );
          }
        },
      ),
    );
  }
}