import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:flutter_svg/svg.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/sign_info.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/view_widget/round_button.dart';


class InForPoints extends StatefulWidget {

  final SignInfo signInfo;
  final Function signIn;

  InForPoints(this.signInfo, this.signIn);

  @override
  State<StatefulWidget> createState() {
    return _InForPoints();
  }

}

class _InForPoints extends State<InForPoints> {

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      margin: EdgeInsets.symmetric(horizontal: 14.w, vertical: 6.h),
      padding: EdgeInsets.symmetric(horizontal:12.w, vertical: 16.h),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withAlpha(12),
            offset: Offset(0, 3),
            blurRadius: 14,
            spreadRadius: 0,
          ),
        ],
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.end,
            children: [
              Text(
                S.of(context).qiandaolingjifen,
                style: TextStyle(
                  fontWeight: MyFontWeight.bold,
                  fontSize: 16.sp,
                  color: Color(0xFF4C4C4C),
                ),
              ),
              SizedBox(
                width:3.w,
              ),
              Text(
                S.of(context).lianxuqiandaolingqushuangbeijifen,
                style: TextStyle(
                  fontWeight: MyFontWeight.regular,
                  fontSize: 11.sp,
                  color: Color(0xFFB3B3B3),
                ),
              ),
            ],
          ),
          SizedBox(
            height: 12.h,
          ),
          StaggeredGridView.countBuilder(
            crossAxisCount: 4,
            shrinkWrap: true,
            itemCount: 7,
            mainAxisSpacing: 8,
            crossAxisSpacing: 18,
            padding: EdgeInsets.only(bottom: 32),
            physics: NeverScrollableScrollPhysics(),
            itemBuilder: (context, position) {
              return signInItem(position);
            },
            staggeredTileBuilder: (position) {
              return StaggeredTile.count(position == 6 ? 2 : 1, 1.28);
            },
          ),
          InkWell(
            onTap: widget.signIn,
            child: Container(
              alignment: Alignment.center,
              child: RoundButton(
                width: double.infinity,
                height: 34.h,
                text: (widget.signInfo != null && widget.signInfo.todayHasSignin)
                    ? S.of(context).yiqiandao
                    : "签到",
                textColor: (widget.signInfo != null && widget.signInfo.todayHasSignin)
                        ? Color(0xFFB3B3B3)
                        : Colors.white,
                backgroup: (widget.signInfo != null && widget.signInfo.todayHasSignin)
                    ? Color(0xFFF5F6FA)
                    : Color(0xFF32A060),
                fontSize: 16.sp,
                fontWeight: MyFontWeight.bold,
                padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 6.h),
                radius: 20.w,
              ),
            ),
          ),
        ],
      ),
    );
  }


  Widget signInItem(position) {
    if (position == 6) {
      return Container(
        padding: EdgeInsets.all(4),
        decoration: BoxDecoration(
          color: Color(0xFFF5F6FA),
          borderRadius: BorderRadius.circular(4),
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Expanded(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    "0${position + 1}",
                    style: TextStyle(
                      color: Color(0xFF353535),
                      fontSize: 14.sp,
                      fontWeight: MyFontWeight.medium,
                    ),
                  ),
                  Container(
                    alignment: Alignment.center,
                    height: 30.h,
                    child: Text(
                      S.of(context).shenmijifendali,
                      style: TextStyle(
                        color: Color(0xFF727272),
                        fontWeight: FontWeight.bold,
                        fontSize: 10.sp,
                      ),
                    ),
                  ),
                  Text(
                    "",
                    style: TextStyle(
                      color: Color(0xFF353535),
                      fontSize: 14.sp,
                      fontWeight: MyFontWeight.medium,
                    ),
                  ),
                ],
              ),
              flex: 1,
            ),
            Container(
              alignment: Alignment.center,
              child: Image.asset(
                "assets/image/icon_gold_blessing.webp",
                width: 59,
                height: 59,
              ),
            ),
          ],
        ),
      );
    } else {
      return Container(
        padding: EdgeInsets.all(4),
        decoration: BoxDecoration(
          color: (widget.signInfo != null &&
              widget.signInfo.signInList != null &&
              widget.signInfo.signInList.length > position)
              ? Color(0xFF32A060)
              : Color(0xFFF5F6FA),
          borderRadius: BorderRadius.circular(4),
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              "0${position + 1}",
              style: TextStyle(
                color: (widget.signInfo != null &&
                    widget.signInfo.signInList != null &&
                    widget.signInfo.signInList.length > position)
                    ? Colors.white
                    : Color(0xFF353535),
                fontSize: 14.sp,
                fontWeight: MyFontWeight.medium,
              ),
            ),
            Container(
              alignment: Alignment.center,
              child:  SvgPicture.asset(
                "assets/svg/qiandao.svg",
                width: 30,
                height: 30,
              ),
            ),
            Container(
              alignment: Alignment.center,
              margin: EdgeInsets.only(
                top: 2.h,
              ),
              child: Text(
                (widget.signInfo != null &&
                    widget.signInfo.rewardList != null &&
                    widget.signInfo.rewardList.length > position)
                    ? "+${widget.signInfo.rewardList[position]}"
                    : "+10",
                style: TextStyle(
                  color: (widget.signInfo != null &&
                      widget.signInfo.signInList != null &&
                      widget.signInfo.signInList.length > position)
                      ? Colors.white
                      : Color(0xFF727272),
                  fontSize: 12.sp,
                  fontWeight: MyFontWeight.regular,
                ),
              ),
            ),
          ],
        ),
      );
    }
  }


}