import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:liftmanager/internal/news/model/news_comm_entity.dart';
import 'package:liftmanager/internal/news/news_router.dart';
import 'package:liftmanager/res/colors.dart';
import 'package:liftmanager/routers/fluro_navigator.dart';

const dummyData = ['Salut', 'Bonjour', 'Au revior'];

class NewsRoller extends StatelessWidget {
  final List<NewsItems> newsList;

  NewsRoller(this.newsList);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: 3),
      child: Swiper(
          itemCount: newsList.length,
          scrollDirection: Axis.vertical,
          autoplay: true,
          itemBuilder: (context, index) => InkWell(
                onTap: () {
                  NavigatorUtils.push(context,
                      "${NewsRouter.newsDetail}?id=${newsList[index].id}");
                },
                child: Container(
                  width: MediaQuery.of(context).size.width,
                  padding: EdgeInsets.only(
                    left: ScreenUtil().setWidth(10),
                    right: ScreenUtil().setWidth(10),
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Row(
                        children: [
                          if (index == 0)
                            Container(
                              alignment: Alignment.center,
                              padding: EdgeInsets.symmetric(horizontal: 2),
                              decoration: BoxDecoration(
                                color: Color(0xffFD5D61),
                                borderRadius: BorderRadius.only(
                                  topLeft: Radius.circular(5),
                                  bottomRight: Radius.circular(5),
                                ),
                              ),
                              child: Text(
                                '最新',
                                style: TextStyle(
                                  fontSize: 10,
                                  color: Colors.white,
                                ),
                              ),
                            ),
                          Expanded(
                            child: Text(
                              newsList[index].title,
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              style: TextStyle(fontSize: 14),
                              //                                        overflow: TextOverflow.ellipsis,
                            ),
                          ),
                        ],
                      ),
                      Expanded(
                          child: Text(
                        "${newsList[index].releaseUser}·阅读${newsList[index].lookNum}次·点赞${newsList[index].likeNum}",
                        overflow: TextOverflow.ellipsis,
                        style:
                            TextStyle(fontSize: 12, color: Colours.text_gray),
                      ))
                    ],
                  ),
                ),
              )),
    );
  }
}
