import 'package:flutter/material.dart';

import 'package:cached_network_image/cached_network_image.dart';

import 'package:f0ckapp/models/item.dart';

class MediaTile extends StatelessWidget {
  final MediaItem item;
  const MediaTile({super.key, required this.item});

  @override
  Widget build(BuildContext context) {
    return RepaintBoundary(
      child: InkWell(
        child: Stack(
          fit: StackFit.expand,
          children: [
            CachedNetworkImage(
              imageUrl: item.thumbnailUrl,
              fit: BoxFit.cover,
              placeholder: (context, url) => Container(color: Colors.grey[900]),
              errorWidget: (context, url, error) =>
                  const Icon(Icons.broken_image),
            ),
            Align(
              alignment: Alignment.bottomRight,
              child: Icon(
                Icons.square,
                color: switch (item.mode) {
                  1 => Colors.green,
                  2 => Colors.red,
                  _ => Colors.yellow,
                },
                size: 15.0,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
