import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:news_getx/data/model/news.dart';
import 'package:news_getx/modules/widgets/image.dart';
import 'package:news_getx/theme/app_colors.dart';
import 'package:news_getx/utils/date.dart';

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

  final NewsItem newsItem;

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 161.h,
      padding: EdgeInsets.all(20.w),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // 左侧图
          InkWell(
            onTap: () {
              // 到详情页
            },
            child: SizedBox(
              width: 121.w,
              height: 121.w,
              child: netImageCached(
                newsItem.thumbnail ?? "",
                width: 121.w,
                height: 121.w,
              ),
            ),
          ),

          // 右侧内容
          SizedBox(
            width: 194.w,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                // 作者
                Container(
                  margin: EdgeInsets.all(0),
                  child: Text(
                    newsItem.author ?? '',
                    style: TextStyle(
                      fontFamily: 'Avenir',
                      fontWeight: FontWeight.normal,
                      color: AppColors.thirdElementText,
                      fontSize: 14.sp,
                    ),
                  ),
                ),
                // 标题
                InkWell(
                  onTap: () {
                    // 到详情页
                  },
                  child: Container(
                    margin: EdgeInsets.only(top: 10.h),
                    child: Text(
                      newsItem.title ?? '',
                      overflow: TextOverflow.clip,
                      maxLines: 3,
                      style: TextStyle(
                        fontFamily: 'Montserrat',
                        fontWeight: FontWeight.w500,
                        color: AppColors.primaryText,
                        fontSize: 16.sp,
                      ),
                    ),
                  ),
                ),

                Spacer(),
                // 一行 3 列
                Container(
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      ConstrainedBox(
                        // 分类
                        constraints: BoxConstraints(maxWidth: 60.w),
                        child: Text(
                          newsItem.category ?? "",
                          style: TextStyle(
                            fontFamily: 'Avenir',
                            fontWeight: FontWeight.normal,
                            color: AppColors.secondaryElementText,
                            fontSize: 14.sp,
                            height: 1,
                          ),
                          overflow: TextOverflow.clip,
                          maxLines: 1,
                        ),
                      ),
                      // 添加时间
                      Container(
                        width: 15.w,
                      ),
                      ConstrainedBox(
                        constraints: BoxConstraints(maxWidth: 100.w),
                        child: Text(
                          '• ${timeLineFormat(newsItem.addtime ?? DateTime(0))}',
                          style: TextStyle(
                            fontFamily: 'Avenir',
                            fontWeight: FontWeight.normal,
                            color: AppColors.thirdElementText,
                            fontSize: 14.sp,
                            height: 1,
                          ),
                          overflow: TextOverflow.clip,
                          maxLines: 1,
                        ),
                      ),
                      // 占满剩余空间
                      Spacer(),
                      // 更多
                      InkWell(
                        child: Icon(
                          Icons.more_horiz,
                          color: AppColors.primaryText,
                          size: 24,
                        ),
                        onTap: () {
                          print('查看更多...');
                        },
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
