
import 'package:carousel_slider/carousel_slider.dart';
import 'package:farmer_client/pages/machinery/widgets/DefLayout.dart';
import 'package:farmer_client/pages/machinery/widgets/RoundButton.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:farmer_client/widgets/ExtendContentList.dart';
import 'package:farmer_client/models/entities/ExtendContent.dart';
import 'package:get/get.dart';
import '../../../../models/entities/CardInfo.dart';
import '../../widgets/summary.dart';

Widget page({ required BuildContext context, VoidCallback? handleClick,required String km,required CardInfo item,required List<BannerImageList> bnnerItem,required List<ContentImageList> contentItem}) {


  return DefLayout(
      head: CarouselSlider(
        items: bnnerItem
            .map((item) => Container(
          child: Center(
              child: Image.network(item.url.toString(),
                  fit: BoxFit.fitWidth, width: 370.w)),
        ))
            .toList(),
        options: CarouselOptions(
          autoPlay: true,
          enlargeCenterPage: false, //图片中心放大
          viewportFraction: 1, //每个页面应占据的视口部分。默认为 0.8，这意味着每个页面填充 80% 的轮播。
          // aspectRatio: 1.6,//纵横比
          height: 214.w,
          initialPage: 1, //初始页
        ),
      ),
      children: [
        DefLayout.card(
          top: DefLayout.headHeight - DefLayout.offset,
          padding: EdgeInsets.only(top: 45.w, left: 15.w, right: 15.w, bottom: 20.w),
          child: _content(context, handleClick,item,contentItem,km),
        )
      ]
  );
}

Widget _content(BuildContext context, VoidCallback? handleClick, CardInfo item,List<ContentImageList> contentItem, String km) {
  return Column(
    children: [
     summary(item: item,km:km),
      _sectionHead('农机详情'),
      ExtendContentList(item: contentItem,),
      SizedBox(height: 20.w,),
      RoundButton(text: "预约", onPressed: handleClick,)
    ],
  );
}

Widget _sectionHead(String title) {
  Widget img = SizedBox(
    width: 16.w,
    height: 16.w,
    child: Image.asset('images/decorate.png'),
  );

  return Container(
    padding: EdgeInsets.fromLTRB(0, 20.w, 0, 20.w),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        img,
        SizedBox(width: 20.w),
        Text(title, style: TextStyle(fontSize: 16.sp, color: const Color(0xFF222222), fontWeight: FontWeight.w500),),
        SizedBox(width: 20.w),
        img,
      ],
    ),
  );
}
