import 'package:flutter/material.dart';

import '../../../../common/extension/toFormatedNewsDate.dart';
import '../../../../constants/api_urls.dart';
import '../../data/models/news.dart';

class NewsListItem extends StatelessWidget {
  const NewsListItem({required this.news, super.key});

  final News news;

  @override
  Widget build(BuildContext context) {
    return Card(
      child: ListTile(
        title: Text(news.title ?? 'Kein Titel'),
        leading: Container(
          width: 100,
          height: 200,
          color:
              (news.teaserImage == null) ? Colors.indigo : Colors.transparent,
          child: FadeInImage.assetNetwork(
            image: news.teaserImage != null
                ? news.teaserImage?.imageVariants!['16x9-512'] ??
                    TagesschauApiUrls.placeholderImage
                : news.brandingImage != null
                    ? news.brandingImage?.imageVariants!['original'] ??
                        TagesschauApiUrls.placeholderImage
                    : TagesschauApiUrls.placeholderImage,
            placeholder: 'assets/img/image_placeholder.png',
          ),
        ),
        subtitle: Text(news.date?.toFormattedNewsDate() ?? 'Kein Datum'),
      ),
    );
  }
}
