import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:yumi/ui_kit/components/sc_compontent.dart';
import 'package:yumi/shared/business_logic/models/res/gift_res.dart';
import 'package:yumi/app_localizations.dart';
import 'package:yumi/ui_kit/components/text/sc_text.dart';
import 'package:yumi/shared/data_sources/sources/repositories/sc_gift_repository_imp.dart';

///礼物墙
class SCGiftwallPage extends StatefulWidget {
  String tageId = "";

  SCGiftwallPage(this.tageId);

  @override
  _GiftwallPageState createState() => _GiftwallPageState();
}

class _GiftwallPageState extends State<SCGiftwallPage> {
  List<SocialChatGiftRes> giftWallList = [];

  @override
  void initState() {
    super.initState();
    SCGiftRepositoryImp()
        .giftWall(widget.tageId)
        .then((result) {
          giftWallList = result;
          setState(() {});
        })
        .catchError((e) {});
  }

  @override
  Widget build(BuildContext context) {
    return giftWallList.isEmpty
        ? mainEmpty(
          msg: SCAppLocalizations.of(context)!.noData,
          textColor: Colors.white,
        )
        : SingleChildScrollView(
          child: GridView.builder(
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 4, // 每行2个
              childAspectRatio: 0.82, // 宽高比
              mainAxisSpacing: 10,
              crossAxisSpacing: 10,
            ),
            padding: EdgeInsets.all(10),
            itemCount: giftWallList.length,
            itemBuilder: (context, index) {
              return _buildItem(giftWallList[index]);
            },
          ),
        );
    ;
  }

  Widget _buildItem(SocialChatGiftRes gift) {
    return Column(
      children: [
        Container(
          width: 68.w,
          height: 68.w,
          decoration: BoxDecoration(
            color: Color(0xffD9D9D9),
            borderRadius: BorderRadius.circular(10.w),
          ),
          alignment: Alignment.center,
          child:   netImage(url: gift.giftPhoto ?? "", width: 36.w),
        ),
        SizedBox(height: 9.w),
        text(
          "x ${gift.quantity}",
          fontSize: 13.sp,
          textColor: Colors.white,
        )
      ],
    );
  }
}
