import 'package:auto_size_text/auto_size_text.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:keyboard/base/base_page.dart';
import 'package:keyboard/data/consts/payment_type.dart';
import 'package:keyboard/data/consts/web_url.dart';
import 'package:keyboard/module/store/store_controller.dart';
import 'package:keyboard/module/store/store_user_reviews_bean.dart';
import 'package:keyboard/resource/string.gen.dart';
import 'package:keyboard/widget/platform_util.dart';

import '../../data/bean/goods_info.dart';
import '../../data/consts/constants.dart';
import '../../resource/assets.gen.dart';
import '../../resource/colors.gen.dart';
import '../../router/app_pages.dart';
import '../../utils/count_down_timer.dart';
import '../../utils/date_util.dart';
import '../../widget/horizontal_dashed_line.dart';
import '../../utils/styles.dart';
import '../../widget/click_text_span.dart';
import '../browser/browser_page.dart';

class StorePage extends BasePage<StoreController> {
  const StorePage({super.key});

  static start() {
    Get.toNamed(RoutePath.store);
  }

  @override
  backgroundColor() => const Color(0xFFFFF8D4);

  @override
  bool immersive() {
    return true;
  }

  @override
  Widget buildBody(BuildContext context) {
    Widget bottomArea;
    if (PlatformUtil.isIOS) {
      bottomArea = Column(
        children: [
          // iOS平台的隐私协议和服务条款
          _buildLastBottomCorner(
            child: Container(
              // margin: EdgeInsets.only(left: 16.w),
              child: _buildPrivacy(
                privacyColor: Color(0x99673300),
                mainAxisAlignment: MainAxisAlignment.start,
              ),
            ),
          ),
          // 恢复订阅入口
          _buildRecoverSubscribe(),
          SizedBox(height: 50.h),
        ],
      );
    } else {
      // 安卓端，可以有会员心声和购买须知
      bottomArea = Column(
        children: [
          // 产品描述
          _buildLastBottomCorner(child: _buildVipDesc()),
          SizedBox(height: 32.h),
          _buildUserReviews(),
          SizedBox(height: 20.h),
          _buildUserNotice(),
        ],
      );
    }
    return Stack(
      children: [
        SingleChildScrollView(
          child: Column(
            children: [
              _buildBanner(context),
              SizedBox(height: 12.h),
              _buildGoodsCard(),
              bottomArea,
            ],
          ),
          Positioned(top: 0, left: 0, right: 0, child: _buildTitle()),
          Positioned(
            bottom: 0,
            left: 0,
            right: 0,
            child: _buildBuyButtonCard(),
          ),
        ],
      ),
    );
  }

  _buildTitle() {
    return SafeArea(
      child: Container(
        alignment: Alignment.centerLeft,
        padding: EdgeInsets.only(top: 16.h, left: 16.w, right: 16.w),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            GestureDetector(
              onTap: controller.clickBack,
              child: Assets.images.iconStoreBack.image(
                width: 32.w,
                height: 32.w,
              ),
            ),
            Obx(() {
              return SizedBox(
                height: 32.h,
                child: Row(
                  mainAxisSize: MainAxisSize.min,
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    // 会员状态信息
                    _buildMemberInfo(),
                    SizedBox(width: 8.w),
                    controller.isLogin
                        ? Assets.images.iconMineUserLogged.image(
                      width: 28.w,
                      height: 28.w,
                    )
                        : Assets.images.iconMineUserNoLogin.image(
                      width: 28.w,
                      height: 28.w,
                    ),
                  ],
                ),
              );
            }),
          ],
        ),
      ),
    );
  }

  // 会员信息
  Widget _buildMemberInfo() {
    return Container(
      height: 32.h,
      alignment: Alignment.center,
      padding: EdgeInsets.symmetric(horizontal: 12.w),
      decoration: BoxDecoration(
        color: Colors.black.withAlpha(77),
        borderRadius: BorderRadius.circular(21.r),
      ),
      child: Text.rich(
        TextSpan(children: _getMemberStatusText()),
        textAlign: TextAlign.right,
      ),
    );
  }

  // 会员状态文字逻辑提取
  List<TextSpan> _getMemberStatusText() {
    // 未登录
    if (!controller.isLogin) {
      return [
        TextSpan(
          text: StringName.memberNoLogged,
          style: _vipTextStyle(isHighlight: true),
        ),
        TextSpan(text: StringName.memberCardNoVipDesc, style: _vipTextStyle()),
      ];
    }

    final isMember = controller.memberStatusInfo?.isMember ?? false;
    final isPermanent = controller.memberStatusInfo?.permanent ?? false;
    final username = controller.userInfo?.name ?? '';

    if (isMember) {
      if (isPermanent) {
        return [
          TextSpan(
            text: StringName.memberCardPermanentVipDesc1,
            style: _vipTextStyle(),
          ),
          TextSpan(
            text: StringName.memberCardPermanentVipDesc2,
            style: _vipTextStyle(isHighlight: true),
          ),
        ];
      } else {
        return [
          TextSpan(text: StringName.memberVipDesc, style: _vipTextStyle()),
          TextSpan(
            text: DateUtil.fromMillisecondsSinceEpoch(
              'yyyy.MM.dd',
              controller.memberStatusInfo?.endTimestamp ?? 0,
            ),
            style: _vipTextStyle(isHighlight: true),
          ),
        ];
      }
    }

    // 登录但不是会员
    return [
      TextSpan(
        text: controller.userInfo?.name ?? controller.getUserName(),
        style: _vipTextStyle(isHighlight: true),
      ),
      TextSpan(text: StringName.memberCardNoVipDesc, style: _vipTextStyle()),
    ];
  }

  // 统一的会员状态文本样式
  TextStyle _vipTextStyle({bool isHighlight = false}) {
    return TextStyle(
      color: isHighlight ? const Color(0xFFFFD273) : Colors.white,
      fontSize: 12.sp,
      fontWeight: FontWeight.w400,
    );
  }

  Widget _buildGoodsCard() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 16.w),
      padding: EdgeInsets.only(
        top: 16.h,
        left: 16.w,
        right: 16.w,
        bottom: 24.h,
      ),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(16.r),
          topRight: Radius.circular(16.r),
        ),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Assets.images.iconGoodsInfoTitle.image(
            width: 115.w,
            fit: BoxFit.cover,
          ),
          SizedBox(height: 16.h),
          Obx(() {
            return Column(
              children:
                  controller.filteredGoodsList.mapIndexed((index, item) {
                    return Obx(() {
                      return GestureDetector(
                        onTap: () => controller.onGoodsItemClick(item),
                        child:
                            PlatformUtil.isIOS
                                ? _buildGoodsItemIos(
                                  index,
                                  item,
                                  controller.selectedGoodsInfoItem?.id ==
                                      item.id,
                                )
                                : _buildGoodsItem(
                                  item,
                                  controller.selectedGoodsInfoItem?.id ==
                                      item.id,
                                ),
                      );
                    });
                  }).toList(),
            );
          }),
          // iOS平台的产品描述
          if (PlatformUtil.isIOS) _buildVipDesc(),
          // 非iOS平台，才有支付宝支付和微信支付
          if (!PlatformUtil.isIOS) _buildPayWayCard(),
        ],
      ),
    );
  }

  Widget _buildPayWayCard() {
    return GestureDetector(
      onTap: () => controller.clickPayWaySwitch(),
      child: Container(
        height: 36.h,
        padding: EdgeInsets.symmetric(horizontal: 10.w),
        decoration: ShapeDecoration(
          shape: RoundedRectangleBorder(
            side: BorderSide(width: 1, color: const Color(0xFFECEBE0)),
            borderRadius: BorderRadius.circular(10.r),
          ),
        ),
        child: Row(
          children: [
            Text(
              StringName.storePayWay,
              style: Styles.getTextStyleBlack204W400(14.sp),
            ),
            const Spacer(),
            Obx(() {
              if (controller.selectedPayWay == null) {
                return SizedBox.shrink();
              }
              return Row(
                children: [
                  Image.asset(
                    getPaymentIconPath(
                      payMethod: controller.selectedPayWay!.payMethod,
                      payPlatform: controller.selectedPayWay!.payPlatform,
                    ),
                    width: 20.w,
                    height: 20.w,
                  ),
                  SizedBox(width: 4.w),
                  Text(
                    controller.selectedPayWay?.title ?? '',
                    style: Styles.getTextStyleBlack204W400(14.sp),
                  ),
                  SizedBox(width: 6.w),
                  Assets.images.iconStoreSwitchPay.image(
                    width: 20.w,
                    height: 20.w,
                    fit: BoxFit.fill,
                  ),
                ],
              );
            }),
          ],
        ),
      ),
    );
  }

  /// 商品-iOS端
  Widget _buildGoodsItemIos(int index, GoodsInfo item, bool isSelected) {
    // 第一个商品，才有有倒计时
    bool hasCountdown = index == 0;

    Widget contentWidget = Stack(
      children: [
        Positioned(
          left: 16.w,
          top: 0,
          right: 0,
          bottom: 0,
          child: Row(
            children: [
              // 价格
              RichText(
                text: TextSpan(
                  children: [
                    TextSpan(
                      text: '￥',
                      style: Styles.getTextStyleFF663300W700(14.sp),
                    ),
                    TextSpan(
                      text: item.amountText,
                      style: Styles.getTextStyleFF663300W700(18.sp),
                    ),
                  ],
                ),
              ),
              SizedBox(width: 18.w),
              // 名称和描述
              Column(
                // 垂直居中
                mainAxisAlignment: MainAxisAlignment.center,
                // 水平左对齐
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  // 名称
                  Text(
                    item.name,
                    style: Styles.getTextStyleFF663300W500(15.sp),
                  ),
                  // 描述
                  if (item.mostDesc?.isNotEmpty == true)
                    AutoSizeText(
                      item.mostDesc!,
                      style: TextStyle(
                        color: Color(0x99673300),
                        fontSize: 12.sp,
                        fontWeight: FontWeight.w500,
                        letterSpacing: -0.60,
                      ),
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      // 最小字体
                      minFontSize: 8,
                      // 缩小步长，越小越丝滑
                      stepGranularity: 0.5,
                    ),
                ],
              ),
            ],
          ),
        ),
        // 勾选状态
        Positioned(
          top: 0,
          right: 22.w,
          bottom: 0,
          child: Image(
            image:
                isSelected
                    ? Assets.images.iconStoreGoodsSelectedSymbolIos.provider()
                    : Assets.images.iconStoreGoodsNormalSymbolIos.provider(),
            width: 20.w,
            height: 20.w,
          ),
        ),
        // 倒计时
        Positioned(
          top: 0,
          right: 8,
          child: Visibility(
            visible: hasCountdown,
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  "倒计时",
                  style: TextStyle(
                    color: isSelected ? Color(0xFFFFECBB) : Color(0xFFFF9416),
                    fontSize: 12.sp,
                    fontWeight: FontWeight.w500,
                  ),
                ),
                SizedBox(width: 4.w),
                Container(
                  margin: EdgeInsets.only(top: 2.5.h),
                  child: Obx(() {
                    return Text(
                      CountdownTimer.format(controller.goodsCountdown.value),
                      style: TextStyle(
                        color: isSelected ? ColorName.white : Color(0xFFFF9416),
                        fontSize: 12.sp,
                        fontWeight: FontWeight.w500,
                      ),
                    );
                  }),
                ),
              ],
            ),
          ),
        ),
      ],
    );

    // 最终呈现的内容组件
    Widget resultWidget;
    if (hasCountdown) {
      // 有倒计时的商品，不规则，使用图片背景
      resultWidget = Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            image:
                isSelected
                    ? Assets.images.bgStoreGoodsItemWithCountdownSelectedIos
                        .provider()
                    : Assets.images.bgStoreGoodsItemWithCountdownNormalIos
                        .provider(),
            fit: BoxFit.fill,
          ),
        ),
        child: contentWidget,
      );
    } else {
      // 没有倒计时的商品
      resultWidget = Container(
        decoration: BoxDecoration(
          shape: BoxShape.rectangle,
          borderRadius: BorderRadius.circular(8.r),
          border: Border.all(
            color: isSelected ? Color(0xFFFF9416) : Color(0xFFFEE86B),
            width: 2.w,
          ),
        ),
        child: contentWidget,
      );
    }

    // 最后面背景透出来的颜色
    Decoration bgDecoration;
    if (isSelected) {
      // 渐变背景
      bgDecoration = ShapeDecoration(
        gradient: LinearGradient(
          begin: Alignment(-0.06, 0.50),
          end: Alignment(1.14, 0.50),
          colors: [const Color(0xFFFFF895), const Color(0xFFFFE941)],
        ),
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.r)),
      );
    } else {
      // 纯色背景
      bgDecoration = BoxDecoration(
        color: Color(0xFFFFFEEE),
        borderRadius: BorderRadius.circular(6.r),
      );
    }

    return Container(
      margin: EdgeInsets.only(bottom: 8.h),
      width: 296.w,
      height: 70.h,
      decoration: bgDecoration,
      child: Stack(
        children: [
          // 对勾图片
          Positioned(
            top: 0,
            right: 0,
            bottom: 0,
            child: Assets.images.bgStoreSelectedArrow1Ios.image(
              width: 85.w,
              height: double.infinity,
            ),
          ),
          resultWidget,
        ],
      ),
    );
  }

  /// 商品-Android端
  Widget _buildGoodsItem(GoodsInfo item, bool isSelected) {
    return Container(
      margin: EdgeInsets.only(bottom: 8.h),
      width: 296.w,
      height: 70.h,
      decoration: ShapeDecoration(
        gradient: LinearGradient(
          begin: Alignment(0.77, -0.00),
          end: Alignment(0.77, 1.00),
          colors:
          isSelected
              ? [const Color(0xFFFF9416), const Color(0xFFFF7813)]
              : [const Color(0xFFFEE057), const Color(0xFFFFC400)],
        ),
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(10.r),
        ),
      ),
      child: Row(
        children: [
          Container(
            width: 212.w,
            height: 70.h,
            decoration: ShapeDecoration(
              gradient:
              isSelected
                  ? LinearGradient(
                begin: Alignment(-0.06, 0.50),
                end: Alignment(1.14, 0.50),
                colors: [
                  const Color(0xFFFFF895),
                  const Color(0xFFFFE941),
                ],
              )
                  : null,
              color: isSelected ? null : const Color(0xFFFFFDEE),
              shape: RoundedRectangleBorder(
                side: BorderSide(width: 1, color: const Color(0xFFFEE86B)),
                borderRadius: BorderRadius.circular(isSelected ? 8 : 10.r),
              ),
            ),
            child: Stack(
              children: [
                if (isSelected)
                  IgnorePointer(
                    child: Assets.images.bgStoreSelectedItem.image(
                      width: 212.w,
                      height: 70.h,
                      fit: BoxFit.fill,
                    ),
                  ),
                Padding(
                  padding: EdgeInsets.only(left: 16.w),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Row(
                        children: [
                          RichText(
                            text: TextSpan(
                              children: [
                                TextSpan(
                                  text: '￥',
                                  style: Styles.getTextStyleFF663300W700(14.sp),
                                ),
                                TextSpan(
                                  text: item.priceDescNumber,
                                  style: Styles.getTextStyleFF663300W700(18.sp),
                                ),
                                TextSpan(
                                  text: item.priceDescUnit,
                                  style: Styles.getTextStyleFF663300W400(13.sp),
                                ),
                              ],
                            ),
                          ),
                          if (item.mostDesc?.isNotEmpty == true)
                            Container(
                              constraints: BoxConstraints(
                                minHeight: 20.w,
                                maxHeight: 20.w,
                                minWidth: 40.w,
                                maxWidth: 120.w,
                              ),
                              padding: EdgeInsets.only(
                                left: 16.w,
                                top: 2.h,
                                bottom: 2.h,
                                right: 4.w,
                              ),
                              decoration: BoxDecoration(
                                image: DecorationImage(
                                  image: Assets.images.iconStoreMost.provider(),
                                  fit: BoxFit.fill,
                                  alignment: Alignment.bottomLeft,
                                ),
                              ),
                              child: AutoSizeText(
                                item.mostDesc!,
                                style: TextStyle(
                                  color: Colors.white,
                                  fontSize: 12.sp,
                                  fontWeight: FontWeight.w500,
                                  letterSpacing: -0.60,
                                ),
                                maxLines: 1,
                                overflow: TextOverflow.ellipsis,
                                minFontSize: 8,

                                // 最小字体
                                stepGranularity: 0.5, // 缩小步长，越小越丝滑
                              ),
                            ),
                        ],
                      ),
                      Text(
                        item.description!,
                        style: Styles.getTextStyle99673300W400(12.sp),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
          // 右侧
          Expanded(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Text(
                  item.name,
                  style:
                  isSelected
                      ? Styles.getTextStyleFFECBBW500(15.sp)
                      : Styles.getTextStyleFF663300W500(15.sp),
                ),
                Container(
                  padding: EdgeInsets.symmetric(horizontal: 8.w),
                  decoration: ShapeDecoration(
                    color: isSelected ? const Color(0xFFFFECBB) : null,
                    gradient:
                    isSelected
                        ? null
                        : LinearGradient(
                      begin: Alignment(0.77, -0.00),
                      end: Alignment(0.77, 1.00),
                      colors: [
                        const Color(0xFFFF9416),
                        const Color(0xFFFF7813),
                      ],
                    ),
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(
                        isSelected ? 17.r : 10.r,
                      ),
                    ),
                  ),
                  child: Text(
                    '￥${item.amountText}',
                    textAlign: TextAlign.center,
                    style:
                    isSelected
                        ? Styles.getTextStyleFF7F14W500(12.sp)
                        : Styles.getTextStyleWhiteW500(12.sp),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  /// 最后的底部圆角
  Widget _buildLastBottomCorner({required Widget child}) {
    return Container(
      alignment: Alignment.centerLeft,
      margin: EdgeInsets.symmetric(horizontal: 16.w),
      padding: EdgeInsets.symmetric(horizontal: PlatformUtil.isIOS ? 4.w : 16.w),
      width: double.infinity,
      decoration: ShapeDecoration(
        gradient: LinearGradient(
          begin: Alignment(0.00, 0.50),
          end: Alignment(1.00, 0.50),
          colors: [const Color(0x7FFFF3A3), const Color(0x21FFF3A3)],
        ),
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.only(
            bottomLeft: Radius.circular(20.r),
            bottomRight: Radius.circular(20.r),
          ),
        ),
        shadows: [
          BoxShadow(
            color: Colors.black.withAlpha(10),
            blurRadius: 10.r,
            spreadRadius: 0.r,
            offset: Offset(0, 8.r),
          ),
        ],
      ),
      child: Column(

      child: child,
    );
  }

  /// 产品描述
  Widget _buildVipDesc() {
    return Obx(() {
      return Text(
        controller.selectedGoodsInfoItem?.selectDesc ?? "",
        style: Styles.getTextStyle99673300W400(12.sp),
      );
    });
  }

  // 轮播图
  Widget _buildBanner(BuildContext context) {
    return SizedBox(
      width: double.infinity,
      child: Stack(
        children: [
          CarouselSlider(
            carouselController: controller.carouselSliderController,
            options: CarouselOptions(
              height: 280.h,
              viewportFraction: 1,
              initialPage: 0,
              enableInfiniteScroll: true,
              reverse: false,
              autoPlay: true,
              autoPlayInterval: const Duration(seconds: 3),
              autoPlayAnimationDuration: const Duration(milliseconds: 800),
              autoPlayCurve: Curves.fastOutSlowIn,
              scrollDirection: Axis.horizontal,
              onPageChanged: (index, reason) {
                controller.onBannerChanged(index, reason);
              },
            ),

            items:
            controller.bannerList.map((item) {
              return item.banner.image(
                width: double.infinity,
                fit: BoxFit.cover,
              );
            }).toList(),
          ),
          Positioned(bottom: 0, left: 0, right: 0, child: _buildIndicator()),
        ],
      ),
    );
  }

  // 指示器
  _buildIndicator() {
    return Container(
      height: 36.h,
      margin: EdgeInsets.symmetric(horizontal: 16.w),
      decoration: ShapeDecoration(
        color: const Color(0xE5121212),
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(21.r),
        ),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children:
        controller.bannerList
            .asMap()
            .entries
            .map((entry) {
          return Obx(() {
            final isSelectedBanner =
                controller.currentBannerIndex == entry.key;
            return Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                GestureDetector(
                  onTap:
                      () =>
                      controller.carouselSliderController
                          .animateToPage(entry.key),
                  child: SizedBox(
                    width: 100.w,
                    child: Stack(
                      alignment: Alignment.center,
                      clipBehavior: Clip.none,
                      children: [
                        if (isSelectedBanner)
                          Positioned(
                            top: -8.h,
                            child: controller
                                .bannerList[entry.key]
                                .indicatorImg
                                .image(
                              width: 100.w,
                              height: 40.h,
                              fit: BoxFit.fill,
                            ),
                          )
                        else
                          Text(
                            controller.bannerList[entry.key].unSelectedDesc,
                            style: Styles.getTextStyleWhiteW400(14.sp),
                          ),
                      ],
                    ),
                  ),
                ),
                if (entry.key != controller.bannerList.length - 1)
                  Padding(
                    padding: EdgeInsets.only(left: 4.w),
                    child: Assets.images.iconStoreDivider.image(
                      width: 2.w,
                      height: 17.h,
                      fit: BoxFit.fill,
                    ),
                  ),
              ],
            );
          });
        }).toList(),
      ),
    );
  }

  Widget _buildUserReviews() {
    return Container(
      width: double.infinity,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Assets.images.iconStoreUserReviewsTitle.image(
            width: 240.w,
            fit: BoxFit.cover,
          ),
          SizedBox(height: 16.h),
          Container(
            width: double.infinity,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(19.r),
              gradient: LinearGradient(
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
                colors: [Colors.white, Color(0xfffff8d4)],
              ),
            ),
            child: Column(
              children: [
                SizedBox(height: 20.h),
                Container(
                  width: 326.w,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(19.r),
                    image: DecorationImage(
                      alignment: Alignment.topCenter,
                      image: Assets.images.bgStoreUserReviews.provider(),
                      fit: BoxFit.contain,
                    ),
                  ),
                  child: Column(
                    children: [
                      Container(
                        padding: EdgeInsets.only(left: 16.w),
                        alignment: Alignment.centerLeft,
                        height: 39.h,
                        child: Assets.images.iconStoreUserReviewsLogo.image(
                          width: 92.w,
                          height: 24.h,
                        ),
                      ),
                      Container(
                        width: 326.w,
                        decoration: ShapeDecoration(
                          color: Colors.white,
                          shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(16.r),
                          ),
                          shadows: [
                            BoxShadow(
                              color: Colors.black.withAlpha(10),
                              blurRadius: 10.r,
                              spreadRadius: 0.r,
                              offset: Offset(0, 5.r),
                            ),
                          ],
                        ),
                        child: Column(
                          children:
                          controller.userReviewsList.map((item) {
                            return _buildReviewsItem(item);
                          }).toList(),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildReviewsItem(StoreUserReviewsBean item) {
    return Container(
      padding: EdgeInsets.only(left: 16.w, right: 16.w, top: 12.h),

      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              item.avatar.image(width: 28.w, height: 28.h, fit: BoxFit.cover),
              SizedBox(width: 10.w),
              Text(
                item.userName,
                style: Styles.getTextStyleBlack204W500(14.sp),
              ),
              SizedBox(width: 6.w),
              Assets.images.iconStorePermanentMember.image(
                width: 70.w,
                height: 20.h,
                fit: BoxFit.cover,
              ),
            ],
          ),
          SizedBox(height: 4.h),
          Padding(
            padding: EdgeInsets.only(left: 38.w),
            child: Text(
              item.userReviews,
              style: TextStyle(
                color: Colors.black.withAlpha(153),
                fontSize: 12.sp,
                fontWeight: FontWeight.w400,
              ),
            ),
          ),
          SizedBox(height: 12.h),

          if (controller.userReviewsList.indexOf(item) !=
              controller.userReviewsList.length - 1)
            HorizontalDashedLine(
              width: 304.w,
              color: const Color(0XFFEDEBE1),
              strokeWidth: 2.h,
              dashLength: 4.w,
              dashSpace: 4.w,
            ),
        ],
      ),
    );
  }

  //  用户须知
  Widget _buildUserNotice() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 16.w),

      decoration: BoxDecoration(borderRadius: BorderRadius.circular(16.r)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text('购买须知', style: Styles.getTextStyleFF663300W400(12.sp)),
          SizedBox(height: 8.h),
          Obx(() {
            return Text(
              controller.configRepository.memberTips.value,
              style: Styles.getTextStyle99673300W400(10.sp),
            );
          }),
          SizedBox(height: 150.h),
        ],
      ),
    );
  }

  /// 恢复订阅
  Widget _buildRecoverSubscribe() {
    return Container(
      margin: EdgeInsets.only(left: 16.w, top: 8.h, right: 16.w),
      child: Row(
        children: [
          Text(
            "⚠️  订阅未生效？点此试试",
            style: TextStyle(
              color: Color(0xFF666355),
              fontSize: 13.sp,
              fontWeight: FontWeight.w400,
            ),
          ),
          GestureDetector(
            onTap: () {
              // 恢复订阅
              controller.clickRecoverSubscribe();
            },
            child: Text(
              "  恢复订阅>",
              style: TextStyle(
                color: Color(0xFF479DF7),
                fontSize: 13.sp,
                fontWeight: FontWeight.w400,
              ),
            ),
          ),
        ],
      ),
    );
  }

  /// 恢复订阅
  Widget _buildRecoverSubscribe() {
    return Container(
      margin: EdgeInsets.only(left: 16.w, top: 8.h, right: 16.w),
      child: Row(
        children: [
          Text(
            "⚠️  订阅未生效？点此试试",
            style: TextStyle(
              color: Color(0xFF666355),
              fontSize: 13.sp,
              fontWeight: FontWeight.w400,
            ),
          ),
          GestureDetector(
            onTap: () {
              // 恢复订阅
              controller.clickRecoverSubscribe();
            },
            child: Text(
              "  恢复订阅>",
              style: TextStyle(
                color: Color(0xFF479DF7),
                fontSize: 13.sp,
                fontWeight: FontWeight.w400,
              ),
            ),
          ),
        ],
      ),
    );
  }

  /// 恢复订阅
  Widget _buildRecoverSubscribe() {
    return Container(
      margin: EdgeInsets.only(left: 16.w, top: 8.h, right: 16.w),
      child: Row(
        children: [
          Text(
            "⚠️  订阅未生效？点此试试",
            style: TextStyle(
              color: Color(0xFF666355),
              fontSize: 13.sp,
              fontWeight: FontWeight.w400,
            ),
          ),
          GestureDetector(
            onTap: () {
              // 恢复订阅
              controller.clickRecoverSubscribe();
            },
            child: Text(
              "  恢复订阅>",
              style: TextStyle(
                color: Color(0xFF479DF7),
                fontSize: 13.sp,
                fontWeight: FontWeight.w400,
              ),
            ),
          ),
        ],
      ),
    );
  }

  /// 恢复订阅
  Widget _buildRecoverSubscribe() {
    return Container(
      margin: EdgeInsets.only(left: 16.w, top: 8.h, right: 16.w),
      child: Row(
        children: [
          Text(
            "⚠️  订阅未生效？点此试试",
            style: TextStyle(
              color: Color(0xFF666355),
              fontSize: 13.sp,
              fontWeight: FontWeight.w400,
            ),
          ),
          GestureDetector(
            onTap: () {
              // 恢复订阅
            },
            child: Text(
              "  恢复订阅>",
              style: TextStyle(
                color: Color(0xFF479DF7),
                fontSize: 13.sp,
                fontWeight: FontWeight.w400,
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildBuyButtonCard() {
    return Container(
      width: 360.w,
      padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 11.h),
      decoration: ShapeDecoration(
        color: Colors.white,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(24.r),
            topRight: Radius.circular(24.r),
          ),
        ),
        shadows: [
          BoxShadow(
            color: Color(0x99FFE498),
            blurRadius: 20,
            offset: Offset(0, 0),
            spreadRadius: 0,
          ),
        ],
      ),
      child: Column(
        children: [
          GestureDetector(
            onTap: controller.clickPayNow,
            child: Container(
              alignment: Alignment.topCenter,
              width: 328.w,
              height: 56.w,
              decoration: ShapeDecoration(
                color: const Color(0xFFFFF587),
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(30.55.r),
                ),
              ),
              child: Container(
                width: 328.w,
                height: 54.w,
                decoration: ShapeDecoration(
                  gradient: LinearGradient(
                    begin: Alignment(0.60, -0.39),
                    end: Alignment(0.60, 0.95),
                    colors: [
                      const Color(0xFFF95FAC),
                      const Color(0xFFFD5E4D),
                      const Color(0xFFFD5E4D),
                      const Color(0xFFFB8A3C),
                    ],
                  ),
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(30.55.r),
                  ),
                ),
                child: Center(
                  child: Text(
                    StringName.storePayNow,
                    style: Styles.getTextStyleWhiteW500(17.sp),
                  ),
                ),
              ),
            ),
          ),

          // 安卓平台的隐私协议和服务条款
          if (!PlatformUtil.isIOS) _buildPrivacy(),
        ],
      ),
    );
  }

  /// 隐私协议和服务条款
  Widget _buildPrivacy({
    Color privacyColor = const Color(0xFF459FFF),
    MainAxisAlignment mainAxisAlignment = MainAxisAlignment.center,
  }) {
    return Row(
      mainAxisAlignment: mainAxisAlignment,
      children: [
        Obx(() {
          return GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTap: () {
              controller.isAgree.value = !controller.isAgree.value;
            },
            child: Padding(
              margin: EdgeInsets.only(top: PlatformUtil.isIOS ? 0.h : 2.h),
              padding: EdgeInsets.symmetric(vertical: 5.w, horizontal: 5.w),
              child:
              controller.isAgree.value
                  ? Assets.images.iconStoreAgreePrivacy.image(
                width: 16.w,
                height: 16.w,
              )
                  : SizedBox(
                child: Container(
                  padding: EdgeInsets.all(1.w),
                  width: 16.w,
                  height: 16.w,
                  child: Container(
                    decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      border: Border.all(
                        color: Colors.black.withAlpha(153),
                        width: 1.w,
                      ),
                    ),
                  ),
                ),
              ),
            ),
          );
        }),
        Transform.translate(
          offset: Offset(-2.w, 0),
          child: Text.rich(
            PlatformUtil.isIOS
                ? TextSpan(
                  children: [
                    TextSpan(
                      text: StringName.textSpanIHaveReadAndAgree,
                      style: TextStyle(
                        color: Colors.black.withAlpha(153),
                        fontSize: 10.sp,
                        fontWeight: FontWeight.w400,
                      ),
                    ),
                    ClickTextSpan(
                      text: StringName.textSpanPrivacyPolicy,
                      url: WebUrl.privacyPolicy,
                      color: privacyColor,
                    ),
                    ClickTextSpan(
                      text: StringName.textSpanServiceTerms,
                      url: WebUrl.serviceAgreement,
                      color: privacyColor,
                    ),
                    TextSpan(
                      text: StringName.textSpanAnd,
                      style: TextStyle(
                        color: Colors.black.withAlpha(153),
                        fontSize: 10.sp,
                        fontWeight: FontWeight.w400,
                      ),
                    ),
                    ClickTextSpan(
                      text: StringName.textSpanMemberAgreement,
                      url: WebUrl.subscribeAgreement,
                      color: privacyColor,
                    ),
                  ],
                )
                : TextSpan(
                  children: [
                    TextSpan(
                      text: StringName.textSpanIHaveReadAndAgree,
                      style: TextStyle(
                        color: Colors.black.withAlpha(153),
                        fontSize: 10.sp,
                        fontWeight: FontWeight.w400,
                      ),
                    ),
                    ClickTextSpan(
                      text: StringName.textSpanPrivacyPolicy,
                      url: WebUrl.privacyPolicy,
                      color: privacyColor,
                    ),

                    TextSpan(
                      text: StringName.textSpanAnd,
                      style: TextStyle(
                        color: Colors.black.withAlpha(153),
                        fontSize: 10.sp,
                        fontWeight: FontWeight.w400,
                      ),
                    ),

                    ClickTextSpan(
                      text: StringName.textSpanServiceTerms,
                      url: WebUrl.serviceAgreement,
                      color: privacyColor,
                    ),
                  ],
                ),
          ),
        ),
      ],
    );
  }
}
